From 77146cf7861f330443f335c98f5bb2d59dde39e3 Mon Sep 17 00:00:00 2001 From: labhvam5 Date: Tue, 19 Dec 2023 16:30:57 +0530 Subject: [PATCH] resolving comments -2 --- apps/mappings/schedules.py | 10 ++++++---- apps/workspaces/apis/import_settings/triggers.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/mappings/schedules.py b/apps/mappings/schedules.py index 942648df..06017674 100644 --- a/apps/mappings/schedules.py +++ b/apps/mappings/schedules.py @@ -1,10 +1,11 @@ from datetime import datetime +from typing import Dict, List from django_q.models import Schedule from apps.workspaces.models import WorkspaceGeneralSettings from fyle_accounting_mappings.models import MappingSetting -def schedule_or_delete_fyle_import_tasks(workspace_general_settings: WorkspaceGeneralSettings, mapping_setting_instance: MappingSetting = None): +def schedule_or_delete_fyle_import_tasks(workspace_general_settings: WorkspaceGeneralSettings, mapping_settings: List[Dict] = []): """ Schedule or delete Fyle import tasks based on the workspace_general_settings and mapping_settings. :param workspace_general_settings: Workspace workspace_general_settings Instance @@ -12,9 +13,10 @@ def schedule_or_delete_fyle_import_tasks(workspace_general_settings: WorkspaceGe :return: None """ task_to_be_scheduled = None - # Check if there is a task to be scheduled - if mapping_setting_instance and mapping_setting_instance.import_to_fyle: - task_to_be_scheduled = mapping_setting_instance + for mapping_setting in mapping_settings: + if mapping_setting['import_to_fyle']: + task_to_be_scheduled = True + break if task_to_be_scheduled or workspace_general_settings.import_categories or workspace_general_settings.import_items: Schedule.objects.update_or_create( diff --git a/apps/workspaces/apis/import_settings/triggers.py b/apps/workspaces/apis/import_settings/triggers.py index c578eb73..c9e7f862 100644 --- a/apps/workspaces/apis/import_settings/triggers.py +++ b/apps/workspaces/apis/import_settings/triggers.py @@ -115,5 +115,5 @@ def post_save_mapping_settings(self, workspace_general_settings_instance: Worksp self.__update_expense_group_settings_for_departments() - new_schedule_or_delete_fyle_import_tasks(workspace_general_settings_instance, None) + new_schedule_or_delete_fyle_import_tasks(workspace_general_settings_instance, self.__mapping_settings) schedule_or_delete_fyle_import_tasks(workspace_general_settings_instance)