From b5c09f3ae418f870a273cdf20ee7f74eb53ec6dd Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:19:09 +0530 Subject: [PATCH] add repetation count (#141) * add repetation count * Fix tests --------- Co-authored-by: GitHub Actions --- .../migrations/0003_error_repetition_count.py | 18 ++++++++++++++++++ apps/accounting_exports/models.py | 8 ++++++++ apps/business_central/exceptions.py | 4 +++- apps/business_central/exports/helpers.py | 7 +++++-- .../0003_remove_expense_settlement_id.py | 17 +++++++++++++++++ tests/test_fyle/fixtures.py | 3 +++ 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 apps/accounting_exports/migrations/0003_error_repetition_count.py create mode 100644 apps/fyle/migrations/0003_remove_expense_settlement_id.py diff --git a/apps/accounting_exports/migrations/0003_error_repetition_count.py b/apps/accounting_exports/migrations/0003_error_repetition_count.py new file mode 100644 index 0000000..f99cdfc --- /dev/null +++ b/apps/accounting_exports/migrations/0003_error_repetition_count.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.2 on 2024-06-14 06:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting_exports', '0002_accountingexport_export_url'), + ] + + operations = [ + migrations.AddField( + model_name='error', + name='repetition_count', + field=models.IntegerField(default=0, help_text='repetition count for the error'), + ), + ] diff --git a/apps/accounting_exports/models.py b/apps/accounting_exports/models.py index 7f41943..651b670 100644 --- a/apps/accounting_exports/models.py +++ b/apps/accounting_exports/models.py @@ -181,9 +181,17 @@ class Error(BaseForeignWorkspaceModel): ExpenseAttribute, on_delete=models.PROTECT, null=True, help_text='Reference to Expense Attribute' ) + repetition_count = models.IntegerField(help_text='repetition count for the error', default=0) is_resolved = BooleanFalseField(help_text='Is resolved') error_title = StringNotNullField(help_text='Error title') error_detail = TextNotNullField(help_text='Error detail') + def increase_repetition_count_by_one(self): + """ + Increase the repetition count by 1. + """ + self.repetition_count += 1 + self.save() + class Meta: db_table = 'errors' diff --git a/apps/business_central/exceptions.py b/apps/business_central/exceptions.py index 6c19178..074a8c2 100644 --- a/apps/business_central/exceptions.py +++ b/apps/business_central/exceptions.py @@ -18,7 +18,9 @@ def handle_business_central_error(exception, accounting_export: AccountingExport business_central_error = str(exception.response) error_msg = 'Failed to create {0}'.format(export_type) - Error.objects.update_or_create(workspace_id=accounting_export.workspace_id, accounting_export=accounting_export, defaults={'error_title': error_msg, 'type': 'BUSINESS_CENTRAL_ERROR', 'error_detail': business_central_error, 'is_resolved': False}) + error, _ = Error.objects.update_or_create(workspace_id=accounting_export.workspace_id, accounting_export=accounting_export, defaults={'error_title': error_msg, 'type': 'BUSINESS_CENTRAL_ERROR', 'error_detail': business_central_error, 'is_resolved': False}) + + error.increase_repetition_count_by_one() accounting_export.status = 'FAILED' accounting_export.detail = None diff --git a/apps/business_central/exports/helpers.py b/apps/business_central/exports/helpers.py index 4c1a23e..86f4056 100644 --- a/apps/business_central/exports/helpers.py +++ b/apps/business_central/exports/helpers.py @@ -75,7 +75,7 @@ def __validate_category_mapping(accounting_export: AccountingExport): }) if category_attribute: - Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=accounting_export.workspace_id, expense_attribute=category_attribute, defaults={ @@ -86,6 +86,8 @@ def __validate_category_mapping(accounting_export: AccountingExport): } ) + error.increase_repetition_count_by_one() + row = row + 1 return bulk_errors @@ -123,7 +125,7 @@ def __validate_employee_mapping(accounting_export: AccountingExport, export_sett }) if employee_attribute: - Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=accounting_export.workspace_id, expense_attribute=employee_attribute, defaults={ @@ -133,6 +135,7 @@ def __validate_employee_mapping(accounting_export: AccountingExport, export_sett 'is_resolved': False } ) + error.increase_repetition_count_by_one() row = row + 1 return bulk_errors diff --git a/apps/fyle/migrations/0003_remove_expense_settlement_id.py b/apps/fyle/migrations/0003_remove_expense_settlement_id.py new file mode 100644 index 0000000..0b91ee7 --- /dev/null +++ b/apps/fyle/migrations/0003_remove_expense_settlement_id.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.2 on 2024-06-14 06:34 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('fyle', '0002_alter_expensefilter_custom_field_type'), + ] + + operations = [ + migrations.RemoveField( + model_name='expense', + name='settlement_id', + ), + ] diff --git a/tests/test_fyle/fixtures.py b/tests/test_fyle/fixtures.py index 70c87ae..8570764 100644 --- a/tests/test_fyle/fixtures.py +++ b/tests/test_fyle/fixtures.py @@ -439,6 +439,7 @@ "is_resolved": "false", "error_title":"Employee Mapping Error", "error_detail":"Employee Mapping Error", + "repetition_count":0, "workspace":1, "accounting_export":"None", "expense_attribute":"None" @@ -451,6 +452,7 @@ "is_resolved": "false", "error_title":"Category Mapping Error", "error_detail":"Category Mapping Error", + "repetition_count":0, "workspace":1, "accounting_export":"None", "expense_attribute":"None" @@ -463,6 +465,7 @@ "is_resolved": "false", "error_title":"Business Central Error", "error_detail":"Busienss Central Error", + "repetition_count":0, "workspace":1, "accounting_export":"None", "expense_attribute":"None"