Skip to content

Commit

Permalink
Setting tax mapping and resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Nov 14, 2023
1 parent db96999 commit 7541063
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions apps/mappings/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 3 additions & 0 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions apps/netsuite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 33 additions & 1 deletion tests/test_mappings/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7541063

Please sign in to comment.