diff --git a/apps/workspaces/apis/import_settings/serializers.py b/apps/workspaces/apis/import_settings/serializers.py index 1dc38ed1..2e4bea52 100644 --- a/apps/workspaces/apis/import_settings/serializers.py +++ b/apps/workspaces/apis/import_settings/serializers.py @@ -92,6 +92,8 @@ def update(self, instance, validated): category_import_log.last_successful_run_at = None category_import_log.save() + pre_save_general_settings = WorkspaceGeneralSettings.objects.filter(workspace_id=instance.id).first() + workspace_general_settings_instance, _ = WorkspaceGeneralSettings.objects.update_or_create( workspace=instance, defaults={ @@ -108,7 +110,7 @@ def update(self, instance, validated): trigger: ImportSettingsTrigger = ImportSettingsTrigger(workspace_general_settings=workspace_general_settings, mapping_settings=mapping_settings, workspace_id=instance.id) - trigger.post_save_workspace_general_settings(workspace_general_settings_instance) + trigger.post_save_workspace_general_settings(workspace_general_settings_instance, pre_save_general_settings) trigger.pre_save_mapping_settings() if workspace_general_settings['import_tax_codes']: diff --git a/apps/workspaces/apis/import_settings/triggers.py b/apps/workspaces/apis/import_settings/triggers.py index 8fc1dd2a..09b24c4f 100644 --- a/apps/workspaces/apis/import_settings/triggers.py +++ b/apps/workspaces/apis/import_settings/triggers.py @@ -1,5 +1,6 @@ from typing import Dict, List +from django_q.tasks import async_task from django.db.models import Q from fyle_accounting_mappings.models import MappingSetting, ExpenseAttribute @@ -70,10 +71,12 @@ def __update_expense_group_settings_for_departments(self): self.add_department_grouping(department_setting['source_field']) - def post_save_workspace_general_settings(self, workspace_general_settings_instance: WorkspaceGeneralSettings): + def post_save_workspace_general_settings(self, workspace_general_settings_instance: WorkspaceGeneralSettings, old_workspace_general_settings: WorkspaceGeneralSettings): """ Post save action for workspace general settings """ + if not workspace_general_settings_instance.import_items and old_workspace_general_settings.import_items: + async_task('fyle_integrations_imports.tasks.disable_items', workspace_id=self.__workspace_id, is_import_enabled=False) new_schedule_or_delete_fyle_import_tasks(workspace_general_settings_instance) def __remove_old_department_source_field(self, current_mappings_settings: List[MappingSetting], new_mappings_settings: List[Dict]): diff --git a/fyle_integrations_imports b/fyle_integrations_imports index 3a7b84d8..f0c509e8 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit 3a7b84d8edc5f5d131441d67c3e4b08b435f4dac +Subproject commit f0c509e8fcfaa2b09ea40473a60bea2383766ee1