From 754106394d70d5253412abf8db8881c070a573d0 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 14 Nov 2023 13:00:04 +0530 Subject: [PATCH] Setting tax mapping and resolve --- apps/mappings/signals.py | 10 +++++++++ apps/mappings/tasks.py | 3 +++ apps/netsuite/tasks.py | 12 ++++++++++ tests/test_mappings/test_signals.py | 34 ++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/apps/mappings/signals.py b/apps/mappings/signals.py index ce85df17..c6fd04f5 100644 --- a/apps/mappings/signals.py +++ b/apps/mappings/signals.py @@ -18,6 +18,16 @@ from .models import GeneralMapping, SubsidiaryMapping from .tasks import schedule_auto_map_ccc_employees +@receiver(post_save, sender=Mapping) +def resolve_post_mapping_errors(sender, instance: Mapping, **kwargs): + """ + Resolve errors after mapping is created + """ + if instance.source_type == 'TAX_GROUP': + Error.objects.filter(expense_attribute_id=instance.source_id).update( + is_resolved=True + ) + @receiver(post_save, sender=CategoryMapping) def resolve_post_category_mapping_errors(sender, instance: Mapping, **kwargs): """ diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index c6c0bff5..1fd0d53e 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -525,6 +525,9 @@ def post_tax_groups(platform_connection: PlatformConnector, workspace_id: int): platform_connection.tax_groups.sync() Mapping.bulk_create_mappings(netsuite_attributes, 'TAX_GROUP', 'TAX_ITEM', workspace_id) + resolve_expense_attribute_errors( + source_attribute_type="TAX_GROUP", workspace_id=workspace_id + ) @handle_exceptions(task_name='Import Category to Fyle and Auto Create Mappings') def auto_create_category_mappings(workspace_id): diff --git a/apps/netsuite/tasks.py b/apps/netsuite/tasks.py index 31ba2197..cfd83232 100644 --- a/apps/netsuite/tasks.py +++ b/apps/netsuite/tasks.py @@ -740,6 +740,18 @@ def __validate_tax_group_mapping(expense_group: ExpenseGroup, configuration: Con 'message': 'Tax Group Mapping not found' }) + if tax_group: + Error.objects.update_or_create( + workspace_id=tax_group.workspace_id, + expense_attribute=tax_group, + defaults={ + 'type': 'TAX_MAPPING', + 'error_title': tax_group.value, + 'error_detail': 'Tax mapping is missing', + 'is_resolved': False + } + ) + row = row + 1 return bulk_errors diff --git a/tests/test_mappings/test_signals.py b/tests/test_mappings/test_signals.py index a71c8292..efccc420 100644 --- a/tests/test_mappings/test_signals.py +++ b/tests/test_mappings/test_signals.py @@ -3,7 +3,39 @@ from apps.workspaces.models import Configuration, Workspace from apps.mappings.models import GeneralMapping from apps.tasks.models import Error -from fyle_accounting_mappings.models import MappingSetting, ExpenseAttribute, EmployeeMapping, CategoryMapping +from fyle_accounting_mappings.models import MappingSetting, ExpenseAttribute, EmployeeMapping, CategoryMapping, Mapping + + +def test_resolve_post_mapping_errors(access_token): + tax_group = ExpenseAttribute.objects.filter( + value='GST: NCF-AU @0.0%', + workspace_id=1, + attribute_type='TAX_GROUP' + ).first() + + Error.objects.update_or_create( + workspace_id=1, + expense_attribute=tax_group, + defaults={ + 'type': 'TAX_GROUP_MAPPING', + 'error_title': tax_group.value, + 'error_detail': 'Tax group mapping is missing', + 'is_resolved': False + } + ) + + mapping = Mapping( + source_type='TAX_GROUP', + destination_type='TAX_DETAIL', + # source__value=source_value, + source_id=1642, + destination_id=1019, + workspace_id=1 + ) + mapping.save() + error = Error.objects.filter(expense_attribute_id=mapping.source_id).first() + + assert error.is_resolved == True @pytest.mark.django_db() def test_resolve_post_category_mapping_errors(access_token):