From 489fe70217865fec2fa4c68442a74f66f32498a4 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Mon, 9 Sep 2024 11:10:22 +0530 Subject: [PATCH 1/7] disable/enable items --- apps/mappings/queues.py | 6 ++++-- fyle_integrations_imports | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/mappings/queues.py b/apps/mappings/queues.py index 3d7ae184..f62fbec4 100644 --- a/apps/mappings/queues.py +++ b/apps/mappings/queues.py @@ -101,8 +101,10 @@ def construct_tasks_and_chain_import_fields_to_fyle(workspace_id): 'is_3d_mapping': False, } - if not workspace_general_settings.import_items: - task_settings['import_items'] = False + # if not workspace_general_settings.import_items: + # task_settings['import_items'] = False + + task_settings['import_items'] = workspace_general_settings.import_items # For now we are only adding PROJECTS support that is why we are hardcoding it if mapping_settings: diff --git a/fyle_integrations_imports b/fyle_integrations_imports index 576dfd46..e1e3cb83 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit 576dfd4678d4b9c0d261543c8b64a926c4e3ff83 +Subproject commit e1e3cb837b5e6e8aefccd90be50c981f41f2ddae From 6dc45f6d0b3b72db2087c726dad7b7999e517941 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Mon, 23 Sep 2024 18:50:27 +0530 Subject: [PATCH 2/7] update submodule --- fyle_integrations_imports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fyle_integrations_imports b/fyle_integrations_imports index e4c2de5f..ca7a3261 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit e4c2de5f794ad34382a1c53631443b7439c6d73f +Subproject commit ca7a3261224c9e5caa7519235fd743949da0bf35 From 4337236a52c86e6ea4d157b650ef8ba6fa5178d1 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Wed, 25 Sep 2024 12:04:11 +0530 Subject: [PATCH 3/7] update submodule --- fyle_integrations_imports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fyle_integrations_imports b/fyle_integrations_imports index ca7a3261..f45a1eef 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit ca7a3261224c9e5caa7519235fd743949da0bf35 +Subproject commit f45a1eefdcd90ea7445c30e09c60404b0f756d27 From 8b86df539168d0617eef865187c0f60f6fd303b3 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Wed, 25 Sep 2024 15:35:00 +0530 Subject: [PATCH 4/7] update submodule --- fyle_integrations_imports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fyle_integrations_imports b/fyle_integrations_imports index f45a1eef..3a7b84d8 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit f45a1eefdcd90ea7445c30e09c60404b0f756d27 +Subproject commit 3a7b84d8edc5f5d131441d67c3e4b08b435f4dac From df88470998f63c819bb96c7132bc8ddc9ad00ebb Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Wed, 25 Sep 2024 16:16:36 +0530 Subject: [PATCH 5/7] add tests for cov --- tests/test_fyle/test_tasks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_fyle/test_tasks.py b/tests/test_fyle/test_tasks.py index 1d34d1e0..37609677 100644 --- a/tests/test_fyle/test_tasks.py +++ b/tests/test_fyle/test_tasks.py @@ -21,7 +21,7 @@ from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings from tests.helper import dict_compare_keys from tests.test_fyle.fixtures import data -from fyle.platform.exceptions import InternalServerError, InvalidTokenError +from fyle.platform.exceptions import InternalServerError, InvalidTokenError, RetryException @pytest.mark.django_db() @@ -40,6 +40,10 @@ def test_create_expense_groups(mocker, db): assert task_log.status == 'COMPLETE' + mock_platform = mocker.patch('apps.fyle.tasks.PlatformConnector') + mock_platform.side_effect = RetryException('Retry Exception') + create_expense_groups(1, ['PERSONAL', 'CCC'], task_log) + fyle_credential = FyleCredential.objects.get(workspace_id=1) fyle_credential.delete() task_log, _ = TaskLog.objects.update_or_create(workspace_id=1, type='FETCHING_EXPENSES', defaults={'status': 'IN_PROGRESS'}) From 7bb42a5fbb9f879d891c8bc7bb8d6d189fd08930 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Wed, 25 Sep 2024 17:37:02 +0530 Subject: [PATCH 6/7] fix: disable items with trigger import settings --- apps/workspaces/apis/import_settings/serializers.py | 4 +++- apps/workspaces/apis/import_settings/triggers.py | 5 ++++- fyle_integrations_imports | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) 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..400712ed 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit 3a7b84d8edc5f5d131441d67c3e4b08b435f4dac +Subproject commit 400712edee329085f35fc5c70a9fc54392a7aaeb From 8acd3b5033a83e7b6ef71a06a7309518cccda312 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Wed, 25 Sep 2024 17:43:27 +0530 Subject: [PATCH 7/7] update submodule --- fyle_integrations_imports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fyle_integrations_imports b/fyle_integrations_imports index 400712ed..f0c509e8 160000 --- a/fyle_integrations_imports +++ b/fyle_integrations_imports @@ -1 +1 @@ -Subproject commit 400712edee329085f35fc5c70a9fc54392a7aaeb +Subproject commit f0c509e8fcfaa2b09ea40473a60bea2383766ee1