Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix disable attribute #222

Merged
merged 12 commits into from
Sep 18, 2024
Merged

fix disable attribute #222

merged 12 commits into from
Sep 18, 2024

Conversation

Hrishabh17
Copy link
Contributor

@Hrishabh17 Hrishabh17 commented Sep 5, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new parameter is_import_to_fyle_enabled across multiple functions, enhancing control over disabling categories, cost centers, merchants, and projects based on import settings.
  • Bug Fixes

    • Improved efficiency and flexibility in handling disabling processes by refining internal logic and conditions.
  • Enhancements

    • Simplified the logic in the update_non_exported_expenses function for better performance and clarity.
    • Enhanced test coverage for expense and accounting export interactions.
    • Added a new method to check import settings, improving data synchronization processes.
    • Updated package versions in requirements.txt for improved functionality and compatibility.

Copy link

coderabbitai bot commented Sep 5, 2024

Warning

Rate limit exceeded

@Hrishabh17 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 6 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 4ccd251 and 2cbfe17.

Walkthrough

The changes involve a simplification of the update_non_exported_expenses function in apps/fyle/tasks.py, which now directly queries the AccountingExport model for expense status instead of relying on accounting_export_summary. This adjustment improves the function's clarity and efficiency. Additionally, the disable_categories, disable_cost_centers, disable_merchants, and disable_projects functions across several files have been modified to include a new parameter, is_import_to_fyle_enabled, enhancing their control flow. Tests have also been updated to reflect these changes, ensuring better coverage.

Changes

Files Change Summary
apps/fyle/tasks.py Simplified the logic in update_non_exported_expenses by querying the AccountingExport model directly for expense status, removing the intermediate variable.
tests/test_fyle/test_tasks.py Enhanced test_update_non_exported_expenses to include a new AccountingExport instance linked to an Expense, improving test coverage and interaction checks.
apps/mappings/imports/modules/categories.py, apps/mappings/imports/modules/cost_centers.py, apps/mappings/imports/modules/merchants.py, apps/mappings/imports/modules/projects.py Modified disable_* functions to include a new parameter is_import_to_fyle_enabled, altering control flow and improving clarity in processing logic.
apps/sage300/utils.py Updated _sync_data method to include is_import_to_fyle_enabled, and added a new method is_imported_enabled for checking import settings.
requirements.txt Upgraded versions of fyle-accounting-mappings and fyle-integrations-platform-connector.

Possibly related PRs

  • Add support for editing expenses #199: This PR modifies the update_non_exported_expenses function in apps/fyle/tasks.py, which is directly related to the changes in the main PR.
  • Fix Edit Expenses changes #204: This PR adds a new argument to the update_non_exported_expenses function, relevant to the changes made in the main PR.
  • Code naming support cost center #210: The changes in this PR enhance the handling of attribute naming conventions, which could be relevant to the logic in the main PR regarding expense processing.

Poem

🐇
In the land of expenses, a change has been made,
With queries direct, no longer delayed.
Bunnies rejoice, for the logic is clear,
Processing smoothly, let’s give a cheer!
With tests that now cover the paths we explore,
Hopping through code, we’ll always want more!
🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Sep 5, 2024

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.404s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Outside diff range, codebase verification and nitpick comments (3)
apps/mappings/imports/modules/merchants.py (2)

Line range hint 78-104: Approve the addition of is_import_to_fyle_enabled and early exit logic.

The addition of the is_import_to_fyle_enabled parameter and the early exit logic based on this parameter and the length of merchants_to_disable are good practices that enhance the function's efficiency and control.

Refactor suggestion for conditional checks.

The static analysis tool suggests combining the if branches using the logical or operator to simplify the code.

Apply this diff to refactor the conditional checks:

-        if not use_code_in_naming and merchant_map['value'] == merchant_map['updated_value']:
-            continue
-        elif use_code_in_naming and (merchant_map['value'] == merchant_map['updated_value'] and merchant_map['code'] == merchant_map['update_code']):
-            continue
+        if (not use_code_in_naming and merchant_map['value'] == merchant_map['updated_value']) or (use_code_in_naming and merchant_map['value'] == merchant_map['updated_value'] and merchant_map['code'] == merchant_map['update_code']):
+            continue

This change simplifies the logic by combining the conditions into a single line, making it easier to read and maintain.

Tools
Ruff

100-103: Combine if branches using logical or operator

Combine if branches

(SIM114)


78-78: Verify the impact of the removed parameter in construct_fyle_payload.

The removal of is_auto_sync_status_allowed from construct_fyle_payload affects multiple test cases and potentially other logic in the codebase. Ensure that all tests and dependent logic are updated to accommodate this change.

  • Check the following test files for necessary updates:
    • tests/test_mappings/test_imports/test_modules/test_cost_centers.py
    • tests/test_mappings/test_imports/test_modules/test_merchants.py
    • tests/test_mappings/test_imports/test_modules/test_categories.py
    • tests/test_mappings/test_imports/test_modules/test_projects.py
Analysis chain

Verify the impact of the removed parameter in construct_fyle_payload.

The removal of is_auto_sync_status_allowed from construct_fyle_payload might affect other parts of the codebase where this method is used.

Run the following script to verify the usage of construct_fyle_payload:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `construct_fyle_payload` and check if the removed parameter affects other parts of the codebase.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 $'construct_fyle_payload'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage of `construct_fyle_payload` and check if the removed parameter affects other parts of the codebase.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 $'construct_fyle_payload'

Length of output: 16056

apps/sage300/utils.py (1)

Line range hint 134-163: Review of _sync_data method changes

The addition of the is_import_to_fyle_enabled parameter is well-integrated into the method. This allows for conditional processing of data synchronization based on the import settings, aligning with the PR objectives.

However, consider improving the readability of the conditional checks by using a more concise approach for checking if source_type is in ATTRIBUTE_CALLBACK_MAP.

Consider using the get method with a default value to simplify the conditional logic:

- if source_type in ATTRIBUTE_CALLBACK_MAP.keys():
+ if ATTRIBUTE_CALLBACK_MAP.get(source_type):
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d01e6c6 and 31a4239.

Files selected for processing (10)
  • apps/mappings/imports/modules/categories.py (3 hunks)
  • apps/mappings/imports/modules/cost_centers.py (4 hunks)
  • apps/mappings/imports/modules/merchants.py (2 hunks)
  • apps/mappings/imports/modules/projects.py (5 hunks)
  • apps/sage300/utils.py (7 hunks)
  • requirements.txt (1 hunks)
  • tests/test_mappings/test_imports/test_modules/test_categories.py (3 hunks)
  • tests/test_mappings/test_imports/test_modules/test_cost_centers.py (3 hunks)
  • tests/test_mappings/test_imports/test_modules/test_merchants.py (3 hunks)
  • tests/test_sage300/test_helpers.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • requirements.txt
Additional context used
Ruff
apps/mappings/imports/modules/merchants.py

100-103: Combine if branches using logical or operator

Combine if branches

(SIM114)

apps/mappings/imports/modules/cost_centers.py

92-95: Combine if branches using logical or operator

Combine if branches

(SIM114)

apps/mappings/imports/modules/categories.py

116-119: Combine if branches using logical or operator

Combine if branches

(SIM114)

apps/mappings/imports/modules/projects.py

110-113: Combine if branches using logical or operator

Combine if branches

(SIM114)

tests/test_sage300/test_helpers.py

145-145: Pointless comparison. Did you mean to assign a value? Otherwise, prepend assert or remove it.

(B015)

apps/sage300/utils.py

342-346: Combine if branches using logical or operator

Combine if branches

(SIM114)

Additional comments not posted (12)
apps/mappings/imports/modules/cost_centers.py (1)

Line range hint 68-96: Refactor conditional logic and verify new parameter integration.

The addition of the is_import_to_fyle_enabled parameter and the new conditional logic in the disable_cost_centers function are significant changes. Here are some observations and suggestions:

  1. Parameter Integration:

    • The new parameter is_import_to_fyle_enabled is used to conditionally skip the disabling of cost centers. This is a sensible addition for enhancing control based on external configurations. Ensure that all calls to this function across the codebase are updated to pass this new parameter where necessary.
    • **** Verify the integration of the new parameter across the codebase:
  2. Conditional Logic Refinement:

    • The logic to skip processing based on use_code_in_naming and the values of value, updated_value, code, and update_code is crucial for avoiding unnecessary operations. However, the static analysis tool suggests combining the if branches for clarity and efficiency.
    • **** Refactor the conditional checks to use a single if statement with logical operators, which will simplify the code and potentially improve readability:
      -if not use_code_in_naming and cost_center_map['value'] == cost_center_map['updated_value']:
      -    continue
      -elif use_code_in_naming and (cost_center_map['value'] == cost_center_map['updated_value'] and cost_center_map['code'] == cost_center_map['update_code']):
      -    continue
      +if (not use_code_in_naming and cost_center_map['value'] == cost_center_map['updated_value']) or \
      +   (use_code_in_naming and cost_center_map['value'] == cost_center_map['updated_value'] and cost_center_map['code'] == cost_center_map['update_code']):
      +    continue
  3. Logging and Error Handling:

    • The function logs various states, which is good for debugging and monitoring. However, consider adding more detailed error handling or recovery mechanisms if the disabling process encounters issues beyond just logging.

Overall, these changes enhance the function's flexibility and efficiency but require careful integration and testing to ensure they work as intended in the broader system.

Also applies to: 108-110

apps/mappings/imports/modules/categories.py (2)

93-93: Addition of new optional parameter is_import_to_fyle_enabled.

The addition of the is_import_to_fyle_enabled parameter allows for conditional processing based on import settings. This is a positive change as it adds flexibility to the function without breaking existing functionality due to its default value of False.


105-107: Efficient early return logic.

The early return based on is_import_to_fyle_enabled and the emptiness of categories_to_disable enhances efficiency by preventing unnecessary processing. This is a good use of short-circuiting in conditional checks.

tests/test_mappings/test_imports/test_modules/test_cost_centers.py (1)

121-121: Verify integration and suggest additional test cases for the new parameter.

The new parameter is_import_to_fyle_enabled is correctly integrated into the disable_cost_centers function calls. However, the test only covers scenarios where this parameter is set to True. Consider adding additional test cases to cover scenarios where is_import_to_fyle_enabled is False or not provided, to ensure comprehensive test coverage.

Would you like me to help draft these additional test cases?

Also applies to: 134-134, 170-170

apps/mappings/imports/modules/projects.py (4)

80-80: Parameter Addition: is_import_to_fyle_enabled

The addition of the is_import_to_fyle_enabled parameter is well implemented with a default value of False. This allows existing calls to the function to remain functional without modification, adhering to backward compatibility.


95-97: Early Exit Optimization

The early exit when is_import_to_fyle_enabled is False or projects_to_disable is empty is a good practice. It prevents unnecessary processing and API calls, enhancing performance and reducing costs.


127-129: Code Clarity Improvement

The loop that iterates over projects_to_disable and maps project names to their destination IDs is clear and improves readability by using meaningful variable names.


154-155: Post-Processing Sync Call

The call to platform.projects.sync() after updating and disabling cost codes ensures that the state is consistent across the platform. This is a good practice in ensuring data integrity.

tests/test_mappings/test_imports/test_modules/test_merchants.py (1)

158-158: Approve the addition of the new parameter in test cases.

The addition of is_import_to_fyle_enabled=True in the disable_merchants function calls within the test cases is consistent with the PR objectives and enhances the function's flexibility. The test assertions are appropriately checking the function's behavior with the new parameter.

Consider verifying the integration of the new parameter across other test cases or functions if not covered. This ensures that the new parameter's addition is consistently handled throughout the application.

Also applies to: 171-171, 199-199

tests/test_mappings/test_imports/test_modules/test_categories.py (1)

180-180: Verify the correct usage and impact of the new parameter is_import_to_fyle_enabled.

The addition of the is_import_to_fyle_enabled parameter to the disable_categories function calls needs to be verified for correctness and consistency. Ensure that the new parameter is being used as intended within the function and that it does not alter the expected behavior of the function in unintended ways.

Run the following script to verify the function usage:

Also applies to: 193-193, 226-226

Verification successful

The new parameter is_import_to_fyle_enabled is correctly used in test cases.

The disable_categories function is invoked with the is_import_to_fyle_enabled parameter set to True in the test file tests/test_mappings/test_imports/test_modules/test_categories.py. This aligns with the function definition, which includes this parameter with a default value of False. The test cases are consistent with the intended usage of the parameter, and no unintended behavior changes are evident.

  • tests/test_mappings/test_imports/test_modules/test_categories.py: Lines 180, 193, 226
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `disable_categories` match the new signature and check for unintended behavior changes.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 $'disable_categories'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify all function calls to `disable_categories` match the new signature and check for unintended behavior changes.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 $'disable_categories'

Length of output: 3747

tests/test_sage300/test_helpers.py (2)

127-127: Review the function call with the new parameter.

The addition of the is_import_to_fyle_enabled=True parameter to the disable_projects function call aligns with the PR objectives. Ensure that all dependent code and tests are updated to handle this new parameter.


181-181: Verify the return value assertion.

The assertion checks if the disable_projects function returns the expected payload. This is crucial for ensuring that the function behaves as expected with the new parameter.

Consider adding more comprehensive tests to cover various scenarios where is_import_to_fyle_enabled might affect the output differently.

Comment on lines 116 to 119
if not use_code_in_naming and category_map['value'] == category_map['updated_value']:
continue
elif use_code_in_naming and (category_map['value'] == category_map['updated_value'] and category_map['code'] == category_map['update_code']):
continue
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refinement of loop conditions.

The loop conditions have been refined to ensure that categories are only processed if their values have changed. This prevents unnecessary updates and enhances performance. However, the static analysis tool suggests combining these conditions using a logical or operator to simplify the code.

Consider refactoring the conditions to use a single if statement with a logical or, which can make the code cleaner and potentially easier to maintain:

-        if not use_code_in_naming and category_map['value'] == category_map['updated_value']:
-            continue
-        elif use_code_in_naming and (category_map['value'] == category_map['updated_value'] and category_map['code'] == category_map['update_code']):
-            continue
+        if (not use_code_in_naming and category_map['value'] == category_map['updated_value']) or (use_code_in_naming and category_map['value'] == category_map['updated_value'] and category_map['code'] == category_map['update_code']):
+            continue
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not use_code_in_naming and category_map['value'] == category_map['updated_value']:
continue
elif use_code_in_naming and (category_map['value'] == category_map['updated_value'] and category_map['code'] == category_map['update_code']):
continue
if (not use_code_in_naming and category_map['value'] == category_map['updated_value']) or (use_code_in_naming and category_map['value'] == category_map['updated_value'] and category_map['code'] == category_map['update_code']):
continue
Tools
Ruff

116-119: Combine if branches using logical or operator

Combine if branches

(SIM114)

Comment on lines 110 to 113
if not use_code_in_naming and projects_map['value'] == projects_map['updated_value']:
continue
elif use_code_in_naming and (projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
continue
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor Suggestion: Combine Conditional Checks

The separate conditional checks for use_code_in_naming can be combined to simplify the code and reduce complexity.

Consider refactoring the conditionals to use a single line with a logical OR operator, as suggested by the static analysis tool:

-        if not use_code_in_naming and projects_map['value'] == projects_map['updated_value']:
-            continue
-        elif use_code_in_naming and (projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
-            continue
+        if (not use_code_in_naming and projects_map['value'] == projects_map['updated_value']) or (use_code_in_naming and projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
+            continue
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not use_code_in_naming and projects_map['value'] == projects_map['updated_value']:
continue
elif use_code_in_naming and (projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
continue
if (not use_code_in_naming and projects_map['value'] == projects_map['updated_value']) or (use_code_in_naming and projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
continue
Tools
Ruff

110-113: Combine if branches using logical or operator

Combine if branches

(SIM114)

@@ -139,10 +139,10 @@ def test_disable_projects(
}
}

disable_projects(workspace_id, projects_to_disable)
disable_projects(workspace_id, projects_to_disable, is_import_to_fyle_enabled=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the assertions for correctness.

The assertions following the disable_projects function calls have been updated. Ensure that these changes correctly reflect the expected behavior based on the new parameter's influence.

  • Line 144: The assertion for sync_call.call_count being 3 instead of 4 suggests a change in the internal logic when the new parameter is utilized.
  • Line 145: The static analysis tool flagged a potential issue with the comparison. It appears to be a typo or an incomplete statement. This should be an assertion.

Consider correcting the assertion on line 145:

- disable_cost_code_call.call_count == 1
+ assert disable_cost_code_call.call_count == 1

Also applies to: 144-145

Comment on lines +330 to +353
def is_imported_enabled(self, attribute_type, workspace_id):
"""
Check if import is enabled for the attribute type
:param attribute_type: Type of the attribute
:return: Whether import is enabled
"""
is_import_to_fyle_enabled = False

import_settings = ImportSetting.objects.filter(workspace_id=self.workspace_id).first()
if not import_settings:
return is_import_to_fyle_enabled

if attribute_type == 'ACCOUNT' and import_settings.import_categories:
is_import_to_fyle_enabled = True

elif attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants:
is_import_to_fyle_enabled = True

elif attribute_type == 'JOB':
mapping_setting = MappingSetting.objects.filter(workspace_id=workspace_id, destination_field='JOB').first()
if mapping_setting and mapping_setting.import_to_fyle:
is_import_to_fyle_enabled = True

return is_import_to_fyle_enabled
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of is_imported_enabled method

The method effectively encapsulates the logic for checking import settings based on the attribute type, enhancing code readability and maintainability.

However, the static analysis tool suggests a potential improvement:

  • Combine similar if branches to simplify the conditional logic.

Refactor the method to combine similar conditions, improving the clarity and reducing redundancy:

- if attribute_type == 'ACCOUNT' and import_settings.import_categories:
-     is_import_to_fyle_enabled = True
- elif attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants:
-     is_import_to_fyle_enabled = True
+ if (attribute_type == 'ACCOUNT' and import_settings.import_categories) or \
+    (attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants):
+    is_import_to_fyle_enabled = True
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def is_imported_enabled(self, attribute_type, workspace_id):
"""
Check if import is enabled for the attribute type
:param attribute_type: Type of the attribute
:return: Whether import is enabled
"""
is_import_to_fyle_enabled = False
import_settings = ImportSetting.objects.filter(workspace_id=self.workspace_id).first()
if not import_settings:
return is_import_to_fyle_enabled
if attribute_type == 'ACCOUNT' and import_settings.import_categories:
is_import_to_fyle_enabled = True
elif attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants:
is_import_to_fyle_enabled = True
elif attribute_type == 'JOB':
mapping_setting = MappingSetting.objects.filter(workspace_id=workspace_id, destination_field='JOB').first()
if mapping_setting and mapping_setting.import_to_fyle:
is_import_to_fyle_enabled = True
return is_import_to_fyle_enabled
def is_imported_enabled(self, attribute_type, workspace_id):
"""
Check if import is enabled for the attribute type
:param attribute_type: Type of the attribute
:return: Whether import is enabled
"""
is_import_to_fyle_enabled = False
import_settings = ImportSetting.objects.filter(workspace_id=self.workspace_id).first()
if not import_settings:
return is_import_to_fyle_enabled
if (attribute_type == 'ACCOUNT' and import_settings.import_categories) or \
(attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants):
is_import_to_fyle_enabled = True
elif attribute_type == 'JOB':
mapping_setting = MappingSetting.objects.filter(workspace_id=workspace_id, destination_field='JOB').first()
if mapping_setting and mapping_setting.import_to_fyle:
is_import_to_fyle_enabled = True
return is_import_to_fyle_enabled
Tools
Ruff

342-346: Combine if branches using logical or operator

Combine if branches

(SIM114)

Copy link

github-actions bot commented Sep 5, 2024

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.874s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
apps/mappings/imports/modules/projects.py (1)

Line range hint 80-158: Function disable_projects Review:

The addition of the new parameter is_import_to_fyle_enabled enhances the control flow by allowing the function to skip disabling projects when not necessary. This change is well-integrated into the existing logic and improves the function's efficiency and adaptability.

Regarding the conditional checks at lines 110-113, the static analysis tool suggests combining them using a logical or operator to simplify the code. This suggestion is valid and would reduce complexity.

Consider refactoring the conditionals to use a single line with a logical OR operator, as suggested by the static analysis tool:

-        if not use_code_in_naming and projects_map['value'] == projects_map['updated_value']:
-            continue
-        elif use_code_in_naming and (projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
-            continue
+        if (not use_code_in_naming and projects_map['value'] == projects_map['updated_value']) or (use_code_in_naming and projects_map['value'] == projects_map['updated_value'] and projects_map['code'] == projects_map['update_code']):
+            continue
Tools
Ruff

110-113: Combine if branches using logical or operator

Combine if branches

(SIM114)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 31a4239 and 98b4ce6.

Files selected for processing (1)
  • apps/mappings/imports/modules/projects.py (5 hunks)
Additional context used
Ruff
apps/mappings/imports/modules/projects.py

110-113: Combine if branches using logical or operator

Combine if branches

(SIM114)

Additional comments not posted (1)
apps/mappings/imports/modules/projects.py (1)

Line range hint 11-78: Class Project Review:

The class Project is well-structured and handles project-related data synchronization effectively. The methods are clear and use descriptive variable names.

Copy link

github-actions bot commented Sep 9, 2024

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.339s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 98b4ce6 and 4aea045.

Files selected for processing (1)
  • requirements.txt (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • requirements.txt

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.760s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 1 ❌ 0 🔥 12.940s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.479s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.226s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.684s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.554s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.523s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.200s ⏱️

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 13.022s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
apps/sage300/utils.py (1)

330-353: Approve the addition of is_imported_enabled method.

The is_imported_enabled method effectively encapsulates the logic for checking import settings based on the attribute type, enhancing code readability and maintainability.

However, the static analysis tool suggests a potential improvement:

  • Combine similar if branches to simplify the conditional logic.

Refactor the method to combine similar conditions, improving the clarity and reducing redundancy:

- if attribute_type == 'ACCOUNT' and import_settings.import_categories:
-     is_import_to_fyle_enabled = True
- 
- elif attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants:
-     is_import_to_fyle_enabled = True
+ if (attribute_type == 'ACCOUNT' and import_settings.import_categories) or \
+    (attribute_type == 'VENDOR' and import_settings.import_vendors_as_merchants):
+     is_import_to_fyle_enabled = True
Tools
Ruff

342-346: Combine if branches using logical or operator

Combine if branches

(SIM114)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7641ef2 and 4ccd251.

Files selected for processing (1)
  • apps/sage300/utils.py (7 hunks)
Additional context used
Ruff
apps/sage300/utils.py

342-346: Combine if branches using logical or operator

Combine if branches

(SIM114)

Additional comments not posted (1)
apps/sage300/utils.py (1)

Line range hint 134-177: LGTM!

The addition of the is_import_to_fyle_enabled parameter enhances the flexibility and adaptability of the _sync_data function. By integrating import settings into the synchronization logic, the function can now dynamically adapt its behavior based on the provided flag. This change has a positive impact on the overall synchronization process.

Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.999s ⏱️

This reverts commit 7641ef2.
This reverts commit 4ccd251.
Copy link

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.921s ⏱️

@Hrishabh17 Hrishabh17 merged commit bb32386 into master Sep 18, 2024
1 check passed
Hrishabh17 added a commit that referenced this pull request Sep 18, 2024
* fix disable attribute

* typo fix

* update accounting mappings

* fix return type

* update edit expenses condition

* fix test cases

* fix typo

* bump platform connector version

* loggers for test

* add logger

* Revert "loggers for test"

This reverts commit 7641ef2.

* Revert "add logger"

This reverts commit 4ccd251.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants