-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Dependent Fields Import (#304)
* Adding new Cost Types Model and Test Script * fix table name * sync with generator and new method * almost there, rough version * new table, new api for dependent fields * bump version * almost there . . . * move dependent fields to separate file * incremental fetches, sync, create/update done * Fix exports * fix comments * add sleep and remove cost type from sync * fix broken test and update fixture db * add tests for dependent fields * increase coverage * more more tests --------- Co-authored-by: ashwin1111 <[email protected]>
- Loading branch information
1 parent
b1b4595
commit 8bb7fc6
Showing
30 changed files
with
1,211 additions
and
279 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 |
---|---|---|
|
@@ -161,3 +161,4 @@ docker-compose.yml | |
|
||
# Cache db | ||
cache.db | ||
fyle_integrations_platform_connector/ |
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 @@ | ||
default_app_config = 'apps.fyle.apps.FyleConfig' |
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,34 @@ | ||
# Generated by Django 3.1.14 on 2023-06-13 19:39 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0025_auto_20230417_1124'), | ||
('fyle', '0019_expense_report_title'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='DependentField', | ||
fields=[ | ||
('id', models.AutoField(primary_key=True, serialize=False)), | ||
('is_import_enabled', models.BooleanField(help_text='Is Import Enabled')), | ||
('project_field_id', models.IntegerField(help_text='Fyle Source Field ID')), | ||
('cost_code_field_name', models.CharField(help_text='Fyle Cost Code Field Name', max_length=255)), | ||
('cost_code_field_id', models.IntegerField(help_text='Fyle Cost Code Field ID')), | ||
('cost_type_field_name', models.CharField(help_text='Fyle Cost Type Field Name', max_length=255)), | ||
('cost_type_field_id', models.IntegerField(help_text='Fyle Cost Type Field ID')), | ||
('last_successful_import_at', models.DateTimeField(help_text='Last Successful Import At', null=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, help_text='Created at')), | ||
('updated_at', models.DateTimeField(auto_now=True, help_text='Updated at')), | ||
('workspace', models.OneToOneField(help_text='Reference to Workspace', on_delete=django.db.models.deletion.PROTECT, to='workspaces.workspace')), | ||
], | ||
options={ | ||
'db_table': 'dependent_fields', | ||
}, | ||
), | ||
] |
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,22 @@ | ||
# Generated by Django 3.1.14 on 2023-06-15 08:08 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0025_auto_20230417_1124'), | ||
('fyle', '0020_dependentfield'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel( | ||
old_name='DependentField', | ||
new_name='DependentFieldSetting', | ||
), | ||
migrations.AlterModelTable( | ||
name='dependentfieldsetting', | ||
table='dependent_field_settings', | ||
), | ||
] |
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,59 @@ | ||
""" | ||
Fyle Signal | ||
""" | ||
import logging | ||
|
||
from django.db.models.signals import post_save, pre_save | ||
from django.dispatch import receiver | ||
|
||
from apps.sage_intacct.dependent_fields import create_dependent_custom_field_in_fyle | ||
from apps.sage_intacct.dependent_fields import schedule_dependent_field_imports | ||
|
||
from .helpers import connect_to_platform | ||
from .models import DependentFieldSetting | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
logger.level = logging.INFO | ||
|
||
|
||
@receiver(pre_save, sender=DependentFieldSetting) | ||
def run_pre_save_dependent_field_settings_triggers(sender, instance: DependentFieldSetting, **kwargs): | ||
""" | ||
:param sender: Sender Class | ||
:param instance: Row instance of Sender Class | ||
:return: None | ||
""" | ||
# Patch alert - Skip creating dependent fields if they're already created | ||
if instance.cost_code_field_id: | ||
return | ||
|
||
platform = connect_to_platform(instance.workspace_id) | ||
|
||
instance.project_field_id = platform.expense_fields.get_project_field_id() | ||
|
||
cost_code = create_dependent_custom_field_in_fyle( | ||
workspace_id=instance.workspace_id, | ||
fyle_attribute_type=instance.cost_code_field_name, | ||
platform=platform, | ||
parent_field_id=instance.project_field_id | ||
) | ||
instance.cost_code_field_id = cost_code['data']['id'] | ||
|
||
cost_type = create_dependent_custom_field_in_fyle( | ||
workspace_id=instance.workspace_id, | ||
fyle_attribute_type=instance.cost_type_field_name, | ||
platform=platform, | ||
parent_field_id=instance.cost_code_field_id | ||
) | ||
instance.cost_type_field_id = cost_type['data']['id'] | ||
|
||
|
||
@receiver(post_save, sender=DependentFieldSetting) | ||
def run_post_save_dependent_field_settings_triggers(sender, instance: DependentFieldSetting, **kwargs): | ||
""" | ||
:param sender: Sender Class | ||
:param instance: Row instance of Sender Class | ||
:return: None | ||
""" | ||
schedule_dependent_field_imports(instance.workspace_id, instance.is_import_enabled) |
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
Oops, something went wrong.