Skip to content

Commit

Permalink
add repetation count (#141)
Browse files Browse the repository at this point in the history
* add repetation count

* Fix tests

---------

Co-authored-by: GitHub Actions <integrations@fylehq.com>
  • Loading branch information
ruuushhh and GitHub Actions committed Jul 23, 2024
1 parent 6c6be2b commit 0d9598e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
18 changes: 18 additions & 0 deletions apps/accounting_exports/migrations/0003_error_repetition_count.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
8 changes: 8 additions & 0 deletions apps/accounting_exports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 3 additions & 1 deletion apps/business_central/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions apps/business_central/exports/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -86,6 +86,8 @@ def __validate_category_mapping(accounting_export: AccountingExport):
}
)

error.increase_repetition_count_by_one()

row = row + 1

return bulk_errors
Expand Down Expand Up @@ -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={
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions apps/fyle/migrations/0003_remove_expense_settlement_id.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
3 changes: 3 additions & 0 deletions tests/test_fyle/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 0d9598e

Please sign in to comment.