Skip to content

Commit

Permalink
resolving comments -2
Browse files Browse the repository at this point in the history
  • Loading branch information
labhvam5 committed Dec 19, 2023
1 parent ed93a0d commit 77146cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions apps/mappings/schedules.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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
:param instance: Mapping Setting Instance
: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(
Expand Down
2 changes: 1 addition & 1 deletion apps/workspaces/apis/import_settings/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 77146cf

Please sign in to comment.