Skip to content

Commit

Permalink
Fix category import (#361)
Browse files Browse the repository at this point in the history
* Fix Category Import on addition of chart_of_account

* minor modification to if condition

* modify condition to check for general setting exists

* lint fix

* Modify condition for update
  • Loading branch information
Hrishabh17 authored May 13, 2024
1 parent a3d2ead commit 6637344
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apps/workspaces/apis/import_settings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand Down
13 changes: 13 additions & 0 deletions apps/workspaces/apis/import_settings/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
):
Expand Down

0 comments on commit 6637344

Please sign in to comment.