-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Export Settings validation #797
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
Open
ruuushhh
wants to merge
3
commits into
master
Choose a base branch
from
fix-export-setting-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ def to_internal_value(self, data): | |
| class WorkspaceGeneralSettingsSerializer(serializers.ModelSerializer): | ||
| 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'] | ||
|
|
||
|
|
||
| class ExpenseGroupSettingsSerializer(serializers.ModelSerializer): | ||
|
|
@@ -179,7 +179,7 @@ def update(self, instance, validated): | |
|
|
||
| return instance | ||
|
|
||
| def validate(self, data): | ||
| def validate(self, data): # noqa: C901 | ||
| if not data.get('workspace_general_settings'): | ||
| raise serializers.ValidationError('Workspace general settings are required') | ||
|
|
||
|
|
@@ -188,4 +188,49 @@ def validate(self, data): | |
|
|
||
| if not data.get('general_mappings'): | ||
| raise serializers.ValidationError('General mappings are required') | ||
|
|
||
| general_settings = data.get('workspace_general_settings') | ||
| general_mappings = data.get('general_mappings') | ||
|
|
||
| # Validate based on reimbursable expenses object | ||
| if general_settings.get('reimbursable_expenses_object') == 'BILL': | ||
| 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 BILL type reimbursable expenses') | ||
|
|
||
| elif general_settings.get('reimbursable_expenses_object') == 'CHECK': | ||
| 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 CHECK type reimbursable expenses') | ||
|
|
||
| elif general_settings.get('reimbursable_expenses_object') == 'EXPENSE': | ||
| if not (general_mappings.get('qbo_expense_account', {}).get('id') or general_mappings.get('qbo_expense_account', {}).get('name')): | ||
| raise serializers.ValidationError('Expense Payment Account is required for EXPENSE type reimbursable expenses') | ||
|
|
||
| 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') | ||
|
|
||
| # Validate based on corporate credit card expenses object | ||
| if general_settings.get('corporate_credit_card_expenses_object') == 'BILL': | ||
| 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 BILL type corporate credit card expenses') | ||
| if not (general_mappings.get('default_ccc_vendor', {}).get('id') or general_mappings.get('default_ccc_vendor', {}).get('name')): | ||
| raise serializers.ValidationError('Default Credit Card Vendor is required for BILL type corporate credit card expenses') | ||
|
|
||
| elif general_settings.get('corporate_credit_card_expenses_object') == 'CREDIT CARD PURCHASE': | ||
| 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 CREDIT CARD PURCHASE type expenses') | ||
|
|
||
| elif general_settings.get('corporate_credit_card_expenses_object') == 'DEBIT CARD EXPENSE': | ||
| if not (general_mappings.get('default_debit_card_account', {}).get('id') or general_mappings.get('default_debit_card_account', {}).get('name')): | ||
| 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': | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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') | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add validation for default_tax_code_id as well |
||
| return data | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?