From 3de094bca934445c1e2a90fe9b3f018120652549 Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Tue, 16 May 2023 15:30:17 +0530 Subject: [PATCH] Sync option in Netsuite Integration page should sync in all the dimensions. (#385) * sync mapping data asynchrously when synced * used chain and made the code more readable * check if there are mapping setting --------- Co-authored-by: Ashutosh619-sudo --- apps/netsuite/views.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/netsuite/views.py b/apps/netsuite/views.py index 6db6c50d..1c0769b5 100644 --- a/apps/netsuite/views.py +++ b/apps/netsuite/views.py @@ -9,11 +9,13 @@ from netsuitesdk.internal.exceptions import NetSuiteRequestError -from fyle_accounting_mappings.models import DestinationAttribute +from fyle_accounting_mappings.models import DestinationAttribute, MappingSetting from fyle_accounting_mappings.serializers import DestinationAttributeSerializer from apps.workspaces.models import NetSuiteCredentials, Workspace, Configuration +from django_q.tasks import Chain + from .serializers import NetSuiteFieldSerializer, CustomSegmentSerializer from .tasks import schedule_bills_creation, schedule_expense_reports_creation, schedule_journal_entry_creation,\ create_vendor_payment, check_netsuite_object_status, process_reimbursements, schedule_credit_card_charge_creation @@ -196,6 +198,24 @@ def post(self, request, *args, **kwargs): workspace = Workspace.objects.get(pk=kwargs['workspace_id']) netsuite_credentials = NetSuiteCredentials.objects.get(workspace_id=workspace.id) + + mapping_settings = MappingSetting.objects.filter(workspace_id=workspace.id) + chain = Chain() + + for mapping_setting in mapping_settings: + if mapping_setting.source_field == 'PROJECT': + # run auto_import_and_map_fyle_fields + chain.append('apps.mappings.tasks.auto_import_and_map_fyle_fields', int(workspace.id)) + elif mapping_setting.source_field == 'COST_CENTER': + # run auto_create_cost_center_mappings + chain.append('apps.mappings.tasks.auto_create_cost_center_mappings', int(workspace.id)) + elif mapping_setting.is_custom: + # run async_auto_create_custom_field_mappings + chain.append('apps.mappings.tasks.async_auto_create_custom_field_mappings', int(workspace.id)) + + if chain.length() > 0: + chain.run() + sync_dimensions(netsuite_credentials, workspace.id, dimensions_to_sync) # Update destination_synced_at to current time only when full refresh happens