From 5872f29c2d0ea82adaf6357a7f92f3791c58b23e Mon Sep 17 00:00:00 2001 From: Vishal Pandey Date: Wed, 25 Jan 2023 13:33:15 +0530 Subject: [PATCH] is_simplify_report_closure_enabled integrated (#199) This reverts commit b4e76262aa21ee4073d4ae373c3d127ea595c68f. --- .../migrations/0016_auto_20230117_0616.py | 19 +++++++++++++++++++ apps/fyle/models.py | 10 +++++++++- apps/fyle/tasks.py | 3 ++- .../apis/export_settings/serializers.py | 8 +++++++- ...ings_is_simplify_report_closure_enabled.py | 18 ++++++++++++++++++ apps/workspaces/models.py | 1 + requirements.txt | 3 ++- sql/scripts/017-set-ccc-expense-state.sql | 7 +++++++ .../reset_db_fixtures/reset_db.sql | 15 +++++++++------ tests/test_workspaces/fixtures.py | 1 + .../test_export_settings/fixtures.py | 3 ++- 11 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 apps/fyle/migrations/0016_auto_20230117_0616.py create mode 100644 apps/workspaces/migrations/0032_workspacegeneralsettings_is_simplify_report_closure_enabled.py create mode 100644 sql/scripts/017-set-ccc-expense-state.sql diff --git a/apps/fyle/migrations/0016_auto_20230117_0616.py b/apps/fyle/migrations/0016_auto_20230117_0616.py new file mode 100644 index 00000000..60df775c --- /dev/null +++ b/apps/fyle/migrations/0016_auto_20230117_0616.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.14 on 2023-01-17 06:16 + +import apps.fyle.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fyle', '0015_auto_20221104_1049'), + ] + + operations = [ + migrations.AlterField( + model_name='expensegroupsettings', + name='ccc_expense_state', + field=models.CharField(choices=[('APPROVED', 'APPROVED'), ('PAID', 'PAID'), ('PAYMENT_PROCESSING', 'PAYMENT_PROCESSING')], default=apps.fyle.models.get_default_ccc_expense_state, help_text='state at which the ccc expenses are fetched (PAYMENT_PROCESSING /PAID)', max_length=100, null=True), + ), + ] diff --git a/apps/fyle/models.py b/apps/fyle/models.py index e8a9d737..8e7331aa 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -169,6 +169,14 @@ def get_default_ccc_expense_group_fields(): def get_default_expense_state(): return 'PAYMENT_PROCESSING' +def get_default_ccc_expense_state(): + return 'PAID' + +CCC_EXPENSE_STATE = ( + ('APPROVED', 'APPROVED'), + ('PAID', 'PAID'), + ('PAYMENT_PROCESSING', 'PAYMENT_PROCESSING') +) class ExpenseGroupSettings(models.Model): """ @@ -193,7 +201,7 @@ class ExpenseGroupSettings(models.Model): max_length=100, default=get_default_expense_state, help_text='state at which the reimbursable expenses are fetched (PAYMENT_PROCESSING / PAID)', null=True) ccc_expense_state = models.CharField( - max_length=100, default=get_default_expense_state, + max_length=100, default=get_default_ccc_expense_state, choices=CCC_EXPENSE_STATE, help_text='state at which the ccc expenses are fetched (PAYMENT_PROCESSING /PAID)', null=True) reimbursable_export_date_type = models.CharField(max_length=100, default='current_date', help_text='Export Date') ccc_export_date_type = models.CharField(max_length=100, default='spent_at', help_text='CCC Export Date') diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index bffb51b8..07ce2ab6 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -102,13 +102,14 @@ def async_create_expense_groups(workspace_id: int, fund_source: List[str], task_ if expenses: workspace.last_synced_at = datetime.now() - reimbursable_expenses_count = len(expenses) + reimbursable_expenses_count += len(expenses) if 'CCC' in fund_source: expenses.extend(platform.expenses.get( source_account_type=['PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT'], state=expense_group_settings.ccc_expense_state, settled_at=ccc_last_synced_at if expense_group_settings.ccc_expense_state == 'PAYMENT_PROCESSING' else None, + approved_at=ccc_last_synced_at if expense_group_settings.ccc_expense_state == 'APPROVED' else None, filter_credit_expenses=filter_credit_expenses, last_paid_at=ccc_last_synced_at if expense_group_settings.ccc_expense_state == 'PAID' else None )) diff --git a/apps/workspaces/apis/export_settings/serializers.py b/apps/workspaces/apis/export_settings/serializers.py index bfb88162..5b1f19f6 100644 --- a/apps/workspaces/apis/export_settings/serializers.py +++ b/apps/workspaces/apis/export_settings/serializers.py @@ -29,7 +29,13 @@ class WorkspaceGeneralSettingsSerializer(serializers.ModelSerializer): class Meta: model = WorkspaceGeneralSettings - fields = ['reimbursable_expenses_object', 'corporate_credit_card_expenses_object', 'auto_map_employees'] + fields = [ + 'reimbursable_expenses_object', + 'corporate_credit_card_expenses_object', + 'auto_map_employees', + 'is_simplify_report_closure_enabled' + ] + read_only_fields = ['is_simplify_report_closure_enabled'] class GeneralMappingsSerializer(serializers.ModelSerializer): diff --git a/apps/workspaces/migrations/0032_workspacegeneralsettings_is_simplify_report_closure_enabled.py b/apps/workspaces/migrations/0032_workspacegeneralsettings_is_simplify_report_closure_enabled.py new file mode 100644 index 00000000..17b141f1 --- /dev/null +++ b/apps/workspaces/migrations/0032_workspacegeneralsettings_is_simplify_report_closure_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.14 on 2023-01-19 11:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0031_auto_20221116_0649'), + ] + + operations = [ + migrations.AddField( + model_name='workspacegeneralsettings', + name='is_simplify_report_closure_enabled', + field=models.BooleanField(default=False, help_text='Simplify report closure is enabled'), + ), + ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 996bae57..c748050f 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -123,6 +123,7 @@ class WorkspaceGeneralSettings(models.Model): skip_cards_mapping = models.BooleanField(default=False, help_text='Skip cards mapping') import_tax_codes = models.BooleanField(default=False, help_text='Auto import tax codes to Fyle', null=True) import_customers = models.BooleanField(default=False, help_text='Auto import customers to Fyle') + is_simplify_report_closure_enabled = models.BooleanField(default=False, help_text='Simplify report closure is enabled') created_at = models.DateTimeField(auto_now_add=True, help_text='Created at') updated_at = models.DateTimeField(auto_now=True, help_text='Updated at') charts_of_accounts = ArrayField( diff --git a/requirements.txt b/requirements.txt index 68d21bf8..de73d4eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,8 @@ django-rest-framework==0.1.0 djangorestframework==3.11.2 enum34==1.1.10 future==0.18.2 -fyle-accounting-mappings==1.20.0 +fyle==0.30.0 +fyle-accounting-mappings==1.22.0 fyle-integrations-platform-connector==1.22.0 fyle-rest-auth==1.3.1 gunicorn==20.0.4 diff --git a/sql/scripts/017-set-ccc-expense-state.sql b/sql/scripts/017-set-ccc-expense-state.sql new file mode 100644 index 00000000..e806a787 --- /dev/null +++ b/sql/scripts/017-set-ccc-expense-state.sql @@ -0,0 +1,7 @@ +rollback; +begin; + +update + expense_group_settings +set + ccc_expense_state = expense_state; diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index e83795a8..e4b3f5bb 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 14.2 (Debian 14.2-1.pgdg110+1) --- Dumped by pg_dump version 14.5 (Debian 14.5-1.pgdg100+1) +-- Dumped from database version 15.1 (Debian 15.1-1.pgdg110+1) +-- Dumped by pg_dump version 15.1 (Debian 15.1-1.pgdg100+1) SET statement_timeout = 0; SET lock_timeout = 0; @@ -1387,7 +1387,8 @@ CREATE TABLE public.workspace_general_settings ( charts_of_accounts character varying(100)[] NOT NULL, import_customers boolean NOT NULL, change_accounting_period boolean NOT NULL, - auto_create_merchant_destination_entity boolean NOT NULL + auto_create_merchant_destination_entity boolean NOT NULL, + is_simplify_report_closure_enabled boolean NOT NULL ); @@ -2415,6 +2416,8 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 124 mappings 0007_auto_20221102_0630 2022-11-03 06:28:39.216754+00 125 workspaces 0030_auto_20221102_1924 2022-11-03 06:28:39.245951+00 126 fyle 0015_auto_20221104_1049 2022-11-04 11:04:25.882513+00 +127 workspaces 0031_workspacegeneralsettings_is_simplify_report_closure_enabled 2023-01-11 06:28:22.8634+00 +128 fyle 0016_auto_20230117_0616 2023-01-18 09:08:24.092416+00 \. @@ -4816,8 +4819,8 @@ COPY public.users (password, last_login, id, email, user_id, full_name, active, -- Data for Name: workspace_general_settings; Type: TABLE DATA; Schema: public; Owner: postgres -- -COPY public.workspace_general_settings (id, reimbursable_expenses_object, corporate_credit_card_expenses_object, created_at, updated_at, workspace_id, sync_fyle_to_xero_payments, sync_xero_to_fyle_payments, import_categories, auto_map_employees, auto_create_destination_entity, map_merchant_to_contact, skip_cards_mapping, import_tax_codes, charts_of_accounts, import_customers, change_accounting_period, auto_create_merchant_destination_entity) FROM stdin; -1 PURCHASE BILL BANK TRANSACTION 2022-08-02 20:25:24.644164+00 2022-08-02 20:25:24.644209+00 1 f t t EMAIL t t f t {EXPENSE} t t f +COPY public.workspace_general_settings (id, reimbursable_expenses_object, corporate_credit_card_expenses_object, created_at, updated_at, workspace_id, sync_fyle_to_xero_payments, sync_xero_to_fyle_payments, import_categories, auto_map_employees, auto_create_destination_entity, map_merchant_to_contact, skip_cards_mapping, import_tax_codes, charts_of_accounts, import_customers, change_accounting_period, auto_create_merchant_destination_entity, is_simplify_report_closure_enabled) FROM stdin; +1 PURCHASE BILL BANK TRANSACTION 2022-08-02 20:25:24.644164+00 2022-08-02 20:25:24.644209+00 1 f t t EMAIL t t f t {EXPENSE} t t f f \. @@ -4930,7 +4933,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 37, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 126, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 128, true); -- diff --git a/tests/test_workspaces/fixtures.py b/tests/test_workspaces/fixtures.py index a48a8f25..2722459d 100644 --- a/tests/test_workspaces/fixtures.py +++ b/tests/test_workspaces/fixtures.py @@ -3,6 +3,7 @@ 'id':2, 'reimbursable_expenses_object':'PURCHASE BILL', 'corporate_credit_card_expenses_object':'BANK TRANSACTION', + 'is_simplify_report_closure_enabled': True, 'sync_fyle_to_xero_payments':False, 'sync_xero_to_fyle_payments':True, 'map_merchant_to_contact':True, diff --git a/tests/test_workspaces/test_apis/test_export_settings/fixtures.py b/tests/test_workspaces/test_apis/test_export_settings/fixtures.py index bbec4158..0f7da98a 100644 --- a/tests/test_workspaces/test_apis/test_export_settings/fixtures.py +++ b/tests/test_workspaces/test_apis/test_export_settings/fixtures.py @@ -28,7 +28,8 @@ "workspace_general_settings": { "reimbursable_expenses_object": "PURCHASE BILL", "corporate_credit_card_expenses_object": "BANK TRANSACTION", - "auto_map_employees": "EMAIL" + "auto_map_employees": "EMAIL", + 'is_simplify_report_closure_enabled': True }, "expense_group_settings": { "reimbursable_expense_group_fields": [