Skip to content

Commit

Permalink
Sync option in Netsuite Integration page should sync in all the dimen…
Browse files Browse the repository at this point in the history
…sions. (#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 <[email protected]>
  • Loading branch information
Ashutosh619-sudo and Ashutosh619-sudo authored May 16, 2023
1 parent 7acf2cb commit 3de094b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion apps/netsuite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3de094b

Please sign in to comment.