diff --git a/apps/workspaces/apis/import_settings/serializers.py b/apps/workspaces/apis/import_settings/serializers.py index de55c291..084c1b0b 100644 --- a/apps/workspaces/apis/import_settings/serializers.py +++ b/apps/workspaces/apis/import_settings/serializers.py @@ -108,6 +108,14 @@ def update(self, instance, validated): general_mappings = validated.pop("general_mappings") mapping_settings = validated.pop("mapping_settings") + trigger: ImportSettingsTrigger = ImportSettingsTrigger( + workspace_general_settings=workspace_general_settings, + mapping_settings=mapping_settings, + workspace_id=instance.id, + ) + + trigger.pre_save_workspace_general_settings(workspace_general_settings) + with transaction.atomic(): ( workspace_general_settings_instance, @@ -145,12 +153,6 @@ 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 ) diff --git a/apps/workspaces/apis/import_settings/triggers.py b/apps/workspaces/apis/import_settings/triggers.py index 04ff5704..22f13a7d 100644 --- a/apps/workspaces/apis/import_settings/triggers.py +++ b/apps/workspaces/apis/import_settings/triggers.py @@ -5,6 +5,7 @@ from apps.workspaces.models import WorkspaceGeneralSettings from apps.mappings.schedules import new_schedule_or_delete_fyle_import_tasks +from fyle_integrations_imports.models import ImportLog class ImportSettingsTrigger: @@ -22,6 +23,18 @@ def __init__( self.__mapping_settings = mapping_settings self.__workspace_id = workspace_id + def pre_save_workspace_general_settings(self, workspace_general_settings): + """ + Pre save action for workspace general settings + """ + current_general_settings = WorkspaceGeneralSettings.objects.filter(workspace_id=self.__workspace_id).first() + + if current_general_settings and current_general_settings.charts_of_accounts and current_general_settings.charts_of_accounts != workspace_general_settings.get("charts_of_accounts"): + import_log = ImportLog.objects.filter(workspace_id=self.__workspace_id, attribute_type='CATEGORY').first() + if import_log: + import_log.last_successful_run_at = None + import_log.save() + def post_save_workspace_general_settings( self, workspace_general_settings_instance: WorkspaceGeneralSettings ):