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: Adding default ccc bank account #180

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/business_central/exports/journal_entry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def create_or_update_object(self, accounting_export: AccountingExport, _: Advanc
:return: purchase invoices object
"""
expense = accounting_export.expenses.first()

accounts_payable_account_id = export_settings.default_bank_account_id

if expense.fund_source == 'CCC':
accounts_payable_account_id = export_settings.default_CCC_bank_account_id
Copy link
Contributor

Choose a reason for hiding this comment

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

default_ccc_bank_account_id


Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for missing CCC bank account.

Consider adding validation to handle cases where default_CCC_bank_account_id is None for CCC expenses.

         if expense.fund_source == 'CCC':
+            if not export_settings.default_CCC_bank_account_id:
+                raise ValueError('CCC bank account not configured for workspace')
             accounts_payable_account_id = export_settings.default_CCC_bank_account_id
📝 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 expense.fund_source == 'CCC':
accounts_payable_account_id = export_settings.default_CCC_bank_account_id
if expense.fund_source == 'CCC':
if not export_settings.default_CCC_bank_account_id:
raise ValueError('CCC bank account not configured for workspace')
accounts_payable_account_id = export_settings.default_CCC_bank_account_id

advance_setting = AdvancedSetting.objects.get(workspace_id=accounting_export.workspace_id)

document_number = expense.expense_number
Expand Down
3 changes: 2 additions & 1 deletion apps/business_central/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def format_business_central_fields(self, workspace_id):
"ACCOUNT",
"EMPLOYEE",
"LOCATION",
"COMPANY"
"COMPANY",
"BANK_ACCOUNT"
]
attributes = (
DestinationAttribute.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion apps/fyle/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def format_fyle_fields(self, workspace_id):
Get Fyle Fields
"""

attribute_types = ['CATEGORY', 'PROJECT', 'COST_CENTER', 'TAX_GROUP', 'CORPORATE_CARD', 'MERCHANT']
attribute_types = ['EMPLOYEE', 'CATEGORY', 'PROJECT', 'COST_CENTER', 'TAX_GROUP', 'CORPORATE_CARD', 'MERCHANT']

attributes = ExpenseAttribute.objects.filter(
~Q(attribute_type__in=attribute_types),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.1.2 on 2024-12-11 10:37

from django.db import migrations
import ms_business_central_api.models.fields


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0004_importsetting_charts_of_accounts'),
]

operations = [
migrations.AddField(
model_name='exportsetting',
name='default_CCC_bank_account_id',
field=ms_business_central_api.models.fields.StringNullField(help_text='CCC Bank Account ID', max_length=255, null=True),
),
migrations.AddField(
model_name='exportsetting',
name='default_CCC_bank_account_name',
field=ms_business_central_api.models.fields.StringNullField(help_text='CCC Bank account name', max_length=255, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.2 on 2024-12-12 17:23

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0005_exportsetting_default_ccc_bank_account_id_and_more'),
]

operations = [
migrations.RenameField(
model_name='exportsetting',
old_name='default_CCC_bank_account_id',
new_name='default_ccc_bank_account_id',
),
migrations.RenameField(
model_name='exportsetting',
old_name='default_CCC_bank_account_name',
new_name='default_ccc_bank_account_name',
),
Comment on lines +13 to +22
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Update required: Found reference to old field name in business_central export model

The field default_CCC_bank_account_id in apps/business_central/exports/journal_entry/models.py still uses the old CamelCase naming convention and needs to be updated to match the new snake_case field name from the migration.

  • Update export_settings.default_CCC_bank_account_id to export_settings.default_ccc_bank_account_id in apps/business_central/exports/journal_entry/models.py
🔗 Analysis chain

Verify field name updates across the codebase.

Let's ensure all references to these fields have been updated to use the new snake_case names.


Let's check the content of the file that still contains references to the old field name.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining references to the old CamelCase field names
# which might cause runtime errors if not updated.

echo "Checking for old field name references..."
rg -l "default_CCC_bank_account" \
  --type py \
  --glob '!**/migrations/*.py'

# Check for any Django model or serializer references
ast-grep --pattern 'class $_(models.Model):
  $$$
  default_CCC_bank_account_$_
  $$$'

ast-grep --pattern 'class $_(serializers.ModelSerializer):
  $$$
  default_CCC_bank_account_$_
  $$$'

Length of output: 411


Script:

#!/bin/bash
# Check the content of the file to see the exact usage
rg "default_CCC_bank_account" apps/business_central/exports/journal_entry/models.py -A 2 -B 2

Length of output: 321

]
2 changes: 2 additions & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class ExportSetting(BaseModel):
)
default_bank_account_name = StringNullField(help_text='Bank account name')
default_bank_account_id = StringNullField(help_text='Bank Account ID')
default_ccc_bank_account_name = StringNullField(help_text='CCC Bank account name')
default_ccc_bank_account_id = StringNullField(help_text='CCC Bank Account ID')
reimbursable_expense_state = StringOptionsField(
choices=REIMBURSABLE_EXPENSE_STATE_CHOICES
)
Expand Down
Loading