From 7f08eb615299c84cda0cc2700602ea780af3cbcf Mon Sep 17 00:00:00 2001 From: Ashwin Thanaraj <37061471+ashwin1111@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:18:08 +0530 Subject: [PATCH] Fix refresh dimension for settings non existence case (#327) --- apps/xero/actions.py | 67 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/apps/xero/actions.py b/apps/xero/actions.py index 0bd2b6d1..d4cb7375 100644 --- a/apps/xero/actions.py +++ b/apps/xero/actions.py @@ -47,46 +47,45 @@ def refersh_xero_dimension(workspace_id): mapping_settings = MappingSetting.objects.filter( workspace_id=workspace_id, import_to_fyle=True ) - workspace_general_settings: WorkspaceGeneralSettings = ( - WorkspaceGeneralSettings.objects.get(workspace_id=workspace_id) - ) - chain = Chain() + workspace_general_settings: WorkspaceGeneralSettings = WorkspaceGeneralSettings.objects.filter(workspace_id=workspace_id).first() ALLOWED_SOURCE_FIELDS = [ FyleAttributeEnum.PROJECT, FyleAttributeEnum.COST_CENTER, ] - for mapping_setting in mapping_settings: - if mapping_setting.source_field in ALLOWED_SOURCE_FIELDS or mapping_setting.is_custom: - # run new_schedule_or_delete_fyle_import_tasks - chain.append( - 'fyle_integrations_imports.tasks.trigger_import_via_schedule', - workspace_id, - mapping_setting.destination_field, - mapping_setting.source_field, - 'apps.xero.utils.XeroConnector', - xero_credentials, - [SYNC_METHODS.get(mapping_setting.destination_field.upper(), 'tracking_categories')], - is_auto_sync_allowed(workspace_general_settings, mapping_setting), - False, - None, - mapping_setting.is_custom, - q_options={ - 'cluster': 'import' - } - ) - elif workspace_general_settings.import_suppliers_as_merchants: - # run auto_create_suppliers_as_merchant - chain.append( - "apps.mappings.tasks.auto_create_suppliers_as_merchants", workspace_id, - q_options={ - 'cluster': 'import' - } - ) - - if chain.length() > 0: - chain.run() + if workspace_general_settings: + chain = Chain() + for mapping_setting in mapping_settings: + if mapping_setting.source_field in ALLOWED_SOURCE_FIELDS or mapping_setting.is_custom: + # run new_schedule_or_delete_fyle_import_tasks + chain.append( + 'fyle_integrations_imports.tasks.trigger_import_via_schedule', + workspace_id, + mapping_setting.destination_field, + mapping_setting.source_field, + 'apps.xero.utils.XeroConnector', + xero_credentials, + [SYNC_METHODS.get(mapping_setting.destination_field.upper(), 'tracking_categories')], + is_auto_sync_allowed(workspace_general_settings, mapping_setting), + False, + None, + mapping_setting.is_custom, + q_options={ + 'cluster': 'import' + } + ) + elif workspace_general_settings.import_suppliers_as_merchants: + # run auto_create_suppliers_as_merchant + chain.append( + "apps.mappings.tasks.auto_create_suppliers_as_merchants", workspace_id, + q_options={ + 'cluster': 'import' + } + ) + + if chain.length() > 0: + chain.run() xero_connector.sync_dimensions(workspace_id)