-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapping settings added to import settings
- Loading branch information
Showing
8 changed files
with
225 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
# from datetime import datetime | ||
|
||
# from django_q.models import Schedule | ||
|
||
# from fyle_accounting_mappings.models import MappingSetting | ||
# from apps.fyle.models import DependentFieldSetting | ||
|
||
|
||
# def schedule_or_delete_fyle_import_tasks(workspace_id: int): | ||
# """ | ||
# :param configuration: Workspace Configuration Instance | ||
# :return: None | ||
# """ | ||
# project_mapping = MappingSetting.objects.filter( | ||
# source_field='PROJECT', | ||
# workspace_id=workspace_id, | ||
# import_to_fyle=True | ||
# ).first() | ||
# dependent_fields = DependentFieldSetting.objects.filter(workspace_id=workspace_id, is_import_enabled=True).first() | ||
|
||
# if project_mapping and dependent_fields: | ||
# start_datetime = datetime.now() | ||
# Schedule.objects.update_or_create( | ||
# func='apps.mappings.tasks.auto_import_and_map_fyle_fields', | ||
# args='{}'.format(workspace_id), | ||
# defaults={ | ||
# 'schedule_type': Schedule.MINUTES, | ||
# 'minutes': 24 * 60, | ||
# 'next_run': start_datetime | ||
# } | ||
# ) | ||
# elif not (project_mapping and dependent_fields): | ||
# Schedule.objects.filter( | ||
# func='apps.mappings.tasks.auto_import_and_map_fyle_fields', | ||
# args='{}'.format(workspace_id) | ||
# ).delete() |
19 changes: 19 additions & 0 deletions
19
apps/workspaces/migrations/0003_alter_importsetting_workspace.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.1.2 on 2023-11-06 10:33 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0002_sage300credential_importsetting_fylecredential_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='importsetting', | ||
name='workspace', | ||
field=models.OneToOneField(help_text='Reference to Workspace model', on_delete=django.db.models.deletion.PROTECT, related_name='import_settings', to='workspaces.workspace'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Dict, List | ||
from django.db.models import Q | ||
|
||
# from apps.mappings.helpers import schedule_or_delete_fyle_import_tasks | ||
from fyle_accounting_mappings.models import MappingSetting | ||
|
||
|
||
class ImportSettingsTrigger: | ||
""" | ||
All the post save actions of Import Settings API | ||
""" | ||
def __init__(self, mapping_settings: List[Dict], workspace_id): | ||
self.__mapping_settings = mapping_settings | ||
self.__workspace_id = workspace_id | ||
|
||
def post_save_mapping_settings(self): | ||
""" | ||
Post save actions for mapping settings | ||
Here we need to clear out the data from the mapping-settings table for consecutive runs. | ||
""" | ||
# We first need to avoid deleting mapping-settings that are always necessary. | ||
destination_fields = [ | ||
'ACCOUNT', | ||
'CCC_ACCOUNT', | ||
'CHARGE_CARD_NUMBER', | ||
'EMPLOYEE', | ||
'EXPENSE_TYPE', | ||
'TAX_DETAIL', | ||
'VENDOR' | ||
] | ||
|
||
# Here we are filtering out the mapping_settings payload and adding the destination-fields that are present in the payload | ||
# So that we avoid deleting them. | ||
for setting in self.__mapping_settings: | ||
if setting['destination_field'] not in destination_fields: | ||
destination_fields.append(setting['destination_field']) | ||
|
||
# Now that we have all the system necessary mapping-settings and the mapping-settings in the payload | ||
# This query will take care of deleting all the redundant mapping-settings that are not required. | ||
MappingSetting.objects.filter( | ||
~Q(destination_field__in=destination_fields), | ||
workspace_id=self.__workspace_id | ||
).delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters