Skip to content

Comments

fix: Export Settings validation#797

Open
ruuushhh wants to merge 3 commits intomasterfrom
fix-export-setting-validation
Open

fix: Export Settings validation#797
ruuushhh wants to merge 3 commits intomasterfrom
fix-export-setting-validation

Conversation

@ruuushhh
Copy link
Contributor

@ruuushhh ruuushhh commented Apr 23, 2025

Description

fix: Export Settings validation

Clickup

https://app.clickup.com/t/86cyp2561

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for export settings to ensure all required account mappings are correctly configured for various expense types and employee field mappings.
    • Enhanced error messages provide clearer guidance when mandatory settings are missing.
  • Tests
    • Added comprehensive tests covering export settings validation scenarios for different expense and mapping configurations.

@coderabbitai
Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

The validate method in the ExportSettingsSerializer class was enhanced with comprehensive conditional validation logic. This logic checks for the presence of required configuration keys and ensures that specific account mappings are provided based on the types of reimbursable and corporate credit card expenses, as well as the employee field mapping. If any required mapping is missing, a ValidationError is raised with a descriptive message. The method concludes by returning the validated data. Additionally, test fixtures were updated to include the new employee_field_mapping field, and new tests were added to cover the expanded validation logic.

Changes

File(s) Change Summary
apps/workspaces/apis/export_settings/serializers.py Added employee_field_mapping field to WorkspaceGeneralSettingsSerializer; enhanced validate method in ExportSettingsSerializer with detailed conditional validation logic for required account mappings.
tests/test_workspaces/test_apis/test_clone_settings/fixtures.py Added "employee_field_mapping": "EMPLOYEE" to workspace_general_settings in export settings test fixtures.
tests/test_workspaces/test_apis/test_export_settings/fixtures.py Added 'employee_field_mapping': 'VENDOR' to workspace_general_settings in export settings test fixtures.
tests/test_workspaces/test_apis/test_export_settings/test_views.py Added test_export_settings_validation function to verify new validation rules; updated existing tests to use deep copies to avoid mutation.

Suggested labels

size/S

Suggested reviewers

  • ashwin1111

Poem

In the warren of code, a rabbit did leap,
Through fields of settings, not missing a beat.
With checks and with care, each mapping in sight,
Validation ensured that all was just right.
If something was missing, a message would show—
So data flows smoothly, wherever it goes! 🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

@github-actions github-actions bot added the size/M Medium PR label Apr 23, 2025
@github-actions
Copy link

Tests Skipped Failures Errors Time
282 0 💤 2 ❌ 0 🔥 50.139s ⏱️

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

🧹 Nitpick comments (3)
apps/workspaces/apis/export_settings/serializers.py (3)

182-182: Consider breaking down the validate method into smaller functions

The # noqa: C901 comment indicates high cyclomatic complexity. For better maintainability and testability, consider decomposing this method into smaller, focused helper methods.


197-198: Extract repeated validation pattern to a helper method

The pattern if not (general_mappings.get('X_id') or general_mappings.get('X_name')) is repeated throughout the code. Consider extracting this into a helper method for better readability and maintainability.

def _check_mapping_exists(self, mappings, id_field, name_field):
    """Check if either the ID or name field exists in the mappings."""
    return bool(mappings.get(id_field) or mappings.get(name_field))

# Example usage in validate method:
if not self._check_mapping_exists(general_mappings, 'accounts_payable_id', 'accounts_payable_name'):
    raise serializers.ValidationError('Accounts Payable is required for BILL type reimbursable expenses')

Also applies to: 201-202, 205-206, 210-211, 213-214, 218-222, 224-225, 228-229, 233-234, 238-239


212-213: Simplify nested if statements as flagged by static analysis

The static analysis tool correctly identified nested if statements that could be simplified for better readability.

 elif general_settings.get('reimbursable_expenses_object') == 'JOURNAL ENTRY':
-    if general_settings.get('employee_field_mapping') == 'VENDOR':
-        if not (general_mappings.get('accounts_payable_id') or general_mappings.get('accounts_payable_name')):
+    employee_field_mapping = general_settings.get('employee_field_mapping')
+    if employee_field_mapping == 'VENDOR' and not (general_mappings.get('accounts_payable_id') or general_mappings.get('accounts_payable_name')):
             raise serializers.ValidationError('Accounts Payable is required for JOURNAL ENTRY with VENDOR mapping')
-    elif general_settings.get('employee_field_mapping') == 'EMPLOYEE':
-        if not (general_mappings.get('bank_account_id') or general_mappings.get('bank_account_name')):
+    elif employee_field_mapping == 'EMPLOYEE' and not (general_mappings.get('bank_account_id') or general_mappings.get('bank_account_name')):
             raise serializers.ValidationError('Bank Account is required for JOURNAL ENTRY with EMPLOYEE mapping')

# Similarly for other nested if statements

Also applies to: 232-233, 237-238

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d803426 and 4b7f5d5.

📒 Files selected for processing (1)
  • apps/workspaces/apis/export_settings/serializers.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apps/workspaces/apis/export_settings/serializers.py

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)


237-238: Use a single if statement instead of nested if statements

(SIM102)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pytest
🔇 Additional comments (4)
apps/workspaces/apis/export_settings/serializers.py (4)

192-240: Good implementation of comprehensive validation logic

The new validation logic effectively ensures that all required mappings are present based on different expense types and settings, which should prevent invalid configurations from being saved.

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)


237-238: Use a single if statement instead of nested if statements

(SIM102)


195-240:

Details

✅ Verification successful

Consider adding validation for all possible expense object types

The validation logic checks for specific expense object types, but it's unclear if this is an exhaustive list. Consider adding a default case to handle any unexpected values.


🏁 Script executed:

#!/bin/bash
# Check if there are any other expense object types used in the codebase
echo "Checking for all possible reimbursable expense object types:"
rg -i "reimbursable_expenses_object.*=|reimbursable_expenses_object.*in" --no-heading

echo -e "\nChecking for all possible corporate credit card expense object types:"
rg -i "corporate_credit_card_expenses_object.*=|corporate_credit_card_expenses_object.*in" --no-heading

Length of output: 15098


Expense object validation is exhaustive

The current validation in apps/workspaces/apis/export_settings/serializers.py already covers all reimbursable_expenses_object values (BILL, CHECK, EXPENSE, JOURNAL ENTRY) and all corporate_credit_card_expenses_object values (BILL, CREDIT CARD PURCHASE, DEBIT CARD EXPENSE, JOURNAL ENTRY) used across the codebase. No additional “default” branch is required.

– If new object types are introduced later, please update this validation accordingly.

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)


237-238: Use a single if statement instead of nested if statements

(SIM102)


208-215: 🛠️ Refactor suggestion

Fix potential KeyError for employee_field_mapping

The code assumes employee_field_mapping exists in general_settings when validating JOURNAL ENTRY, but this key may not be present, potentially causing a KeyError.

 elif general_settings.get('reimbursable_expenses_object') == 'JOURNAL ENTRY':
-    if general_settings.get('employee_field_mapping') == 'VENDOR':
+    employee_field_mapping = general_settings.get('employee_field_mapping')
+    if employee_field_mapping == 'VENDOR':
         if not (general_mappings.get('accounts_payable_id') or general_mappings.get('accounts_payable_name')):
             raise serializers.ValidationError('Accounts Payable is required for JOURNAL ENTRY with VENDOR mapping')
-    elif general_settings.get('employee_field_mapping') == 'EMPLOYEE':
+    elif employee_field_mapping == 'EMPLOYEE':
         if not (general_mappings.get('bank_account_id') or general_mappings.get('bank_account_name')):
             raise serializers.ValidationError('Bank Account is required for JOURNAL ENTRY with EMPLOYEE mapping')

Likely an incorrect or invalid review comment.

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-235: 🛠️ Refactor suggestion

Fix potential KeyError for name_in_journal_entry

Similar to the previous issue, there's an assumption that name_in_journal_entry exists in general_settings which could cause a KeyError.

 elif general_settings.get('corporate_credit_card_expenses_object') == 'JOURNAL ENTRY':
-    if general_settings.get('name_in_journal_entry') == 'MERCHANT':
+    name_in_journal_entry = general_settings.get('name_in_journal_entry')
+    if name_in_journal_entry == 'MERCHANT':
         if not (general_mappings.get('default_ccc_account_id') or general_mappings.get('default_ccc_account_name')):
             raise serializers.ValidationError('Default Credit Card Account is required for JOURNAL ENTRY with MERCHANT name')

Likely an incorrect or invalid review comment.

🧰 Tools
🪛 Ruff (0.8.2)

232-233: Use a single if statement instead of nested if statements

(SIM102)

@github-actions
Copy link

Tests Skipped Failures Errors Time
282 0 💤 0 ❌ 0 🔥 32.592s ⏱️

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

🧹 Nitpick comments (4)
apps/workspaces/apis/export_settings/serializers.py (4)

209-215: Consider simplifying nested if statements.

The nested if statements can be simplified to improve readability and maintainability.

-        elif general_settings.get('reimbursable_expenses_object') == 'JOURNAL ENTRY':
-            if general_settings.get('employee_field_mapping') == 'VENDOR':
-                if not (general_mappings.get('accounts_payable', {}).get('id') or general_mappings.get('accounts_payable', {}).get('name')):
-                    raise serializers.ValidationError('Accounts Payable is required for JOURNAL ENTRY with VENDOR mapping')
-            elif general_settings.get('employee_field_mapping') == 'EMPLOYEE':
-                if not (general_mappings.get('bank_account', {}).get('id') or general_mappings.get('bank_account', {}).get('name')):
-                    raise serializers.ValidationError('Bank Account is required for JOURNAL ENTRY with EMPLOYEE mapping')
+        elif general_settings.get('reimbursable_expenses_object') == 'JOURNAL ENTRY':
+            if general_settings.get('employee_field_mapping') == 'VENDOR' and not (general_mappings.get('accounts_payable', {}).get('id') or general_mappings.get('accounts_payable', {}).get('name')):
+                raise serializers.ValidationError('Accounts Payable is required for JOURNAL ENTRY with VENDOR mapping')
+            elif general_settings.get('employee_field_mapping') == 'EMPLOYEE' and not (general_mappings.get('bank_account', {}).get('id') or general_mappings.get('bank_account', {}).get('name')):
+                raise serializers.ValidationError('Bank Account is required for JOURNAL ENTRY with EMPLOYEE mapping')
🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-235: Consider simplifying this nested if statement.

Similar to the earlier suggestion, this nested if statement can be simplified.

-        elif general_settings.get('corporate_credit_card_expenses_object') == 'JOURNAL ENTRY':
-            if general_settings.get('name_in_journal_entry') == 'MERCHANT':
-                if not (general_mappings.get('default_ccc_account', {}).get('id') or general_mappings.get('default_ccc_account', {}).get('name')):
-                    raise serializers.ValidationError('Default Credit Card Account is required for JOURNAL ENTRY with MERCHANT name')
+        elif general_settings.get('corporate_credit_card_expenses_object') == 'JOURNAL ENTRY' and general_settings.get('name_in_journal_entry') == 'MERCHANT':
+            if not (general_mappings.get('default_ccc_account', {}).get('id') or general_mappings.get('default_ccc_account', {}).get('name')):
+                raise serializers.ValidationError('Default Credit Card Account is required for JOURNAL ENTRY with MERCHANT name')
🧰 Tools
🪛 Ruff (0.8.2)

232-233: Use a single if statement instead of nested if statements

(SIM102)


182-241: Consider adding helper methods to improve readability.

The validation method is growing complex (hence the noqa: C901). Consider extracting validation logic into helper methods to improve readability and maintainability.

Example approach:

def validate(self, data):
    self._validate_required_fields(data)
    
    general_settings = data.get('workspace_general_settings')
    general_mappings = data.get('general_mappings')
    
    self._validate_reimbursable_expenses(general_settings, general_mappings)
    self._validate_corporate_card_expenses(general_settings, general_mappings)
    self._validate_tax_settings(general_settings, general_mappings)
    
    return data

def _validate_required_fields(self, data):
    if not data.get('workspace_general_settings'):
        raise serializers.ValidationError('Workspace general settings are required')
    # ... rest of basic validation

def _validate_reimbursable_expenses(self, general_settings, general_mappings):
    # Validation logic for reimbursable expenses

def _validate_corporate_card_expenses(self, general_settings, general_mappings):
    # Validation logic for corporate card expenses

def _validate_tax_settings(self, general_settings, general_mappings):
    # Validation logic for tax settings

This approach would make the code more maintainable while improving unit testing capabilities.

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)


237-238: Use a single if statement instead of nested if statements

(SIM102)


192-240: Consider adding helper function for field existence check.

The pattern not (general_mappings.get('field', {}).get('id') or general_mappings.get('field', {}).get('name')) is repeated frequently. Consider extracting it into a helper method for readability.

def _is_mapping_empty(self, mappings, field_name):
    """Check if a mapping field is empty (has neither id nor name)."""
    field = mappings.get(field_name, {})
    return not (field.get('id') or field.get('name'))

Then you could use it as:

if self._is_mapping_empty(general_mappings, 'accounts_payable'):
    raise serializers.ValidationError('Accounts Payable is required for...')
🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)


237-238: Use a single if statement instead of nested if statements

(SIM102)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 4b7f5d5 and 79edab4.

📒 Files selected for processing (1)
  • apps/workspaces/apis/export_settings/serializers.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apps/workspaces/apis/export_settings/serializers.py

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)


237-238: Use a single if statement instead of nested if statements

(SIM102)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pytest
🔇 Additional comments (4)
apps/workspaces/apis/export_settings/serializers.py (4)

182-191: LGTM! Basic validation checks are comprehensive.

The initial validation ensures all required components are present before proceeding with detailed validation.


192-215: LGTM! Thorough validation for reimbursable expenses based on object type.

The validation logic correctly enforces required mappings for each reimbursable expense object type, ensuring appropriate configuration before saving.

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


216-235: LGTM! Comprehensive validation for corporate card expenses.

The validation ensures that appropriate mappings are configured based on the corporate credit card expense object type.

🧰 Tools
🪛 Ruff (0.8.2)

232-233: Use a single if statement instead of nested if statements

(SIM102)


236-240: LGTM! Tax code validation is appropriately implemented.

The validation ensures that default tax code is provided when tax code import is enabled.

Consider simplifying this nested if statement as well:

-        if general_settings.get('import_tax_codes'):
-            if not (general_mappings.get('default_tax_code', {}).get('id') or general_mappings.get('default_tax_code', {}).get('name')):
-                raise serializers.ValidationError('Default Tax Code is required when tax codes are imported')
+        if general_settings.get('import_tax_codes') and not (general_mappings.get('default_tax_code', {}).get('id') or general_mappings.get('default_tax_code', {}).get('name')):
+            raise serializers.ValidationError('Default Tax Code is required when tax codes are imported')
🧰 Tools
🪛 Ruff (0.8.2)

237-238: Use a single if statement instead of nested if statements

(SIM102)

@github-actions
Copy link

Tests Skipped Failures Errors Time
283 0 💤 0 ❌ 0 🔥 50.888s ⏱️

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

🧹 Nitpick comments (3)
apps/workspaces/apis/export_settings/serializers.py (3)

208-215: Consider simplifying nested if statement.

The nested if statement could be simplified to improve readability.

- if general_settings.get('reimbursable_expenses_object') == 'JOURNAL ENTRY':
-     if general_settings.get('employee_field_mapping') == 'VENDOR':
-         if not (general_mappings.get('accounts_payable', {}).get('id') or general_mappings.get('accounts_payable', {}).get('name')):
-             raise serializers.ValidationError('Accounts Payable is required for JOURNAL ENTRY with VENDOR mapping')
-     elif general_settings.get('employee_field_mapping') == 'EMPLOYEE':
-         if not (general_mappings.get('bank_account', {}).get('id') or general_mappings.get('bank_account', {}).get('name')):
-             raise serializers.ValidationError('Bank Account is required for JOURNAL ENTRY with EMPLOYEE mapping')
+ if general_settings.get('reimbursable_expenses_object') == 'JOURNAL ENTRY':
+     if general_settings.get('employee_field_mapping') == 'VENDOR' and not (general_mappings.get('accounts_payable', {}).get('id') or general_mappings.get('accounts_payable', {}).get('name')):
+         raise serializers.ValidationError('Accounts Payable is required for JOURNAL ENTRY with VENDOR mapping')
+     elif general_settings.get('employee_field_mapping') == 'EMPLOYEE' and not (general_mappings.get('bank_account', {}).get('id') or general_mappings.get('bank_account', {}).get('name')):
+         raise serializers.ValidationError('Bank Account is required for JOURNAL ENTRY with EMPLOYEE mapping')
🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


231-235: Consider simplifying nested if statement.

Similar to the previous suggestion, this nested if statement could be simplified.

- elif general_settings.get('corporate_credit_card_expenses_object') == 'JOURNAL ENTRY':
-     if general_settings.get('name_in_journal_entry') == 'MERCHANT':
-         if not (general_mappings.get('default_ccc_account', {}).get('id') or general_mappings.get('default_ccc_account', {}).get('name')):
-             raise serializers.ValidationError('Default Credit Card Account is required for JOURNAL ENTRY with MERCHANT name')
+ elif general_settings.get('corporate_credit_card_expenses_object') == 'JOURNAL ENTRY' and general_settings.get('name_in_journal_entry') == 'MERCHANT':
+     if not (general_mappings.get('default_ccc_account', {}).get('id') or general_mappings.get('default_ccc_account', {}).get('name')):
+         raise serializers.ValidationError('Default Credit Card Account is required for JOURNAL ENTRY with MERCHANT name')
🧰 Tools
🪛 Ruff (0.8.2)

232-233: Use a single if statement instead of nested if statements

(SIM102)


182-236: Consider refactoring the validation method for better maintainability.

While the validation logic is thorough and well-tested, the method is quite long and complex. Consider refactoring it into smaller, focused methods for better maintainability.

For example, you could create separate methods for validating reimbursable expenses and corporate credit card expenses:

def validate(self, data):
    self._validate_required_fields(data)
    self._validate_reimbursable_expenses(data)
    self._validate_corporate_credit_card_expenses(data)
    return data

def _validate_required_fields(self, data):
    if not data.get('workspace_general_settings'):
        raise serializers.ValidationError('Workspace general settings are required')
    if not data.get('expense_group_settings'):
        raise serializers.ValidationError('Expense group settings are required')
    if not data.get('general_mappings'):
        raise serializers.ValidationError('General mappings are required')

def _validate_reimbursable_expenses(self, data):
    general_settings = data.get('workspace_general_settings')
    general_mappings = data.get('general_mappings')
    
    # Reimbursable expenses validation logic here...

def _validate_corporate_credit_card_expenses(self, data):
    general_settings = data.get('workspace_general_settings')
    general_mappings = data.get('general_mappings')
    
    # Corporate credit card expenses validation logic here...
🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 79edab4 and e93be31.

📒 Files selected for processing (4)
  • apps/workspaces/apis/export_settings/serializers.py (3 hunks)
  • tests/test_workspaces/test_apis/test_clone_settings/fixtures.py (2 hunks)
  • tests/test_workspaces/test_apis/test_export_settings/fixtures.py (2 hunks)
  • tests/test_workspaces/test_apis/test_export_settings/test_views.py (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/test_workspaces/test_apis/test_clone_settings/fixtures.py
  • tests/test_workspaces/test_apis/test_export_settings/fixtures.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_workspaces/test_apis/test_export_settings/test_views.py (1)
tests/conftest.py (2)
  • api_client (28-29)
  • test_connection (33-69)
🪛 Ruff (0.8.2)
apps/workspaces/apis/export_settings/serializers.py

212-213: Use a single if statement instead of nested if statements

(SIM102)


232-233: Use a single if statement instead of nested if statements

(SIM102)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pytest
🔇 Additional comments (8)
tests/test_workspaces/test_apis/test_export_settings/test_views.py (4)

1-1: Good addition of the copy module.

Using deep copies is a good practice to avoid unintended side effects when modifying test data.


28-29: Good implementation of deepcopy for test data.

This ensures that the original test data remains unmodified, preventing potential test interference.


34-41: Good practice using deepcopy for test data manipulation.

The consistent use of deep copies helps maintain test data integrity throughout the test execution.


43-131: Comprehensive test coverage for validation logic.

The new test function thoroughly covers all validation scenarios for different expense types and mappings, ensuring robust validation of export settings. Each test case clearly demonstrates a specific validation rule by:

  1. Setting up the appropriate configuration
  2. Making the API call
  3. Asserting both the status code and error message

This is an excellent approach to validation testing.

apps/workspaces/apis/export_settings/serializers.py (4)

28-28: Good addition of the employee_field_mapping field.

This addition to the serializer fields properly supports the new validation logic.


182-191: Validate method complexity warning suppressed appropriately.

The # noqa: C901 comment acknowledges the complexity of the validation method, which is justified given the comprehensive validation requirements.


192-215: Thorough validation logic for reimbursable expenses.

The validation logic correctly enforces the presence of required fields based on the reimbursable expenses object type, improving the robustness of the application.

🧰 Tools
🪛 Ruff (0.8.2)

212-213: Use a single if statement instead of nested if statements

(SIM102)


216-235: Thorough validation logic for corporate credit card expenses.

The validation logic correctly enforces the presence of required fields based on the corporate credit card expenses object type.

🧰 Tools
🪛 Ruff (0.8.2)

232-233: Use a single if statement instead of nested if statements

(SIM102)

@ruuushhh ruuushhh self-assigned this Apr 24, 2025
@ruuushhh ruuushhh requested a review from ashwin1111 April 24, 2025 16:17
@github-actions
Copy link

Tests Skipped Failures Errors Time
283 0 💤 0 ❌ 0 🔥 49.399s ⏱️

class Meta:
model = WorkspaceGeneralSettings
fields = ['reimbursable_expenses_object', 'corporate_credit_card_expenses_object', 'name_in_journal_entry']
fields = ['reimbursable_expenses_object', 'corporate_credit_card_expenses_object', 'name_in_journal_entry', 'employee_field_mapping']
Copy link
Contributor

Choose a reason for hiding this comment

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

this will be sent in employee_settings call only, why are we updating contracts?

raise serializers.ValidationError('Default Debit Card Account is required for DEBIT CARD EXPENSE type expenses')

elif general_settings.get('corporate_credit_card_expenses_object') == 'JOURNAL ENTRY':
if general_settings.get('name_in_journal_entry') == 'MERCHANT':
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this check added, can you point me to code ref?

if general_settings.get('name_in_journal_entry') == 'MERCHANT':
if not (general_mappings.get('default_ccc_account', {}).get('id') or general_mappings.get('default_ccc_account', {}).get('name')):
raise serializers.ValidationError('Default Credit Card Account is required for JOURNAL ENTRY with MERCHANT name')

Copy link
Contributor

Choose a reason for hiding this comment

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

let's add validation for default_tax_code_id as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR

Development

Successfully merging this pull request may close these issues.

2 participants