From b9214cff545914c8cce8188e75acc3e1b366673f Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Wed, 18 Dec 2024 11:07:26 +0530 Subject: [PATCH] Feat: Add toggle for enabling uploading attachments --- apps/netsuite/tasks.py | 36 ++++++++++--------- ...figuration_is_attachment_upload_enabled.py | 18 ++++++++++ apps/workspaces/models.py | 1 + .../reset_db_fixtures/reset_db.sql | 32 +++++++++-------- tests/test_workspaces/data.json | 3 +- 5 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py diff --git a/apps/netsuite/tasks.py b/apps/netsuite/tasks.py index 85278e0e..78fb313e 100644 --- a/apps/netsuite/tasks.py +++ b/apps/netsuite/tasks.py @@ -510,10 +510,11 @@ def create_bill(expense_group: ExpenseGroup, task_log_id, last_export): logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e) logger.info('Updated Expense Group %s successfully', expense_group.id) - async_task( - 'apps.netsuite.tasks.upload_attachments_and_update_export', - expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id - ) + if configuration.is_attachment_upload_enabled: + async_task( + 'apps.netsuite.tasks.upload_attachments_and_update_export', + expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id + ) @handle_netsuite_exceptions(payment=False) @@ -561,11 +562,12 @@ def create_credit_card_charge(expense_group, task_log_id, last_export): if expense.amount < 0: refund = True - for expense in expense_group.expenses.all(): - attachment_link = load_attachments(netsuite_connection, expense, expense_group, credit_card_charge_object) + if configuration.is_attachment_upload_enabled: + for expense in expense_group.expenses.all(): + attachment_link = load_attachments(netsuite_connection, expense, expense_group, credit_card_charge_object) - if attachment_link: - attachment_links[expense.expense_id] = attachment_link + if attachment_link: + attachment_links[expense.expense_id] = attachment_link created_credit_card_charge = netsuite_connection.post_credit_card_charge( credit_card_charge_object, credit_card_charge_lineitems_objects, general_mappings, attachment_links, refund @@ -659,10 +661,11 @@ def create_expense_report(expense_group, task_log_id, last_export): logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e) worker_logger.info('Updated Expense Group %s successfully', expense_group.id) - async_task( - 'apps.netsuite.tasks.upload_attachments_and_update_export', - expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id - ) + if configuration.is_attachment_upload_enabled: + async_task( + 'apps.netsuite.tasks.upload_attachments_and_update_export', + expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id + ) @@ -724,10 +727,11 @@ def create_journal_entry(expense_group, task_log_id, last_export): logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e) worker_logger.info('Updated Expense Group %s successfully', expense_group.id) - async_task( - 'apps.netsuite.tasks.upload_attachments_and_update_export', - expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id - ) + if configuration.is_attachment_upload_enabled: + async_task( + 'apps.netsuite.tasks.upload_attachments_and_update_export', + expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id + ) def __validate_general_mapping(expense_group: ExpenseGroup, configuration: Configuration) -> List[BulkError]: diff --git a/apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py b/apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py new file mode 100644 index 00000000..ffcb192e --- /dev/null +++ b/apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.14 on 2024-12-18 05:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0040_alter_configuration_change_accounting_period'), + ] + + operations = [ + migrations.AddField( + model_name='configuration', + name='is_attachment_upload_enabled', + field=models.BooleanField(default=True, help_text='Is Attachment upload enabled'), + ), + ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index cef4474a..d9bc5998 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -181,6 +181,7 @@ class Configuration(models.Model): name_in_journal_entry = models.CharField(max_length=100, help_text='Name in jounral entry for ccc expense only', default='MERCHANT',choices=NAME_IN_JOURNAL_ENTRY) allow_intercompany_vendors = models.BooleanField(default=False, help_text='Allow intercompany vendors') je_single_credit_line = models.BooleanField(default=False, help_text='Journal Entry Single Credit Line') + is_attachment_upload_enabled = models.BooleanField(default=True, help_text='Is Attachment upload enabled') class Meta: db_table = 'configurations' diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index 9bf1976e..2cc9ef58 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 15.10 (Debian 15.10-1.pgdg120+1) --- Dumped by pg_dump version 15.9 (Debian 15.9-1.pgdg120+1) +-- Dumped by pg_dump version 15.10 (Debian 15.10-1.pgdg120+1) SET statement_timeout = 0; SET lock_timeout = 0; @@ -323,7 +323,8 @@ CREATE TABLE public.configurations ( import_items boolean NOT NULL, name_in_journal_entry character varying(100) NOT NULL, allow_intercompany_vendors boolean NOT NULL, - je_single_credit_line boolean NOT NULL + je_single_credit_line boolean NOT NULL, + is_attachment_upload_enabled boolean NOT NULL ); @@ -2697,10 +2698,10 @@ COPY public.category_mappings (id, created_at, updated_at, destination_account_i -- Data for Name: configurations; Type: TABLE DATA; Schema: public; Owner: postgres -- -COPY public.configurations (id, reimbursable_expenses_object, corporate_credit_card_expenses_object, created_at, updated_at, workspace_id, sync_fyle_to_netsuite_payments, sync_netsuite_to_fyle_payments, import_projects, auto_map_employees, import_categories, auto_create_destination_entity, auto_create_merchants, employee_field_mapping, import_tax_items, change_accounting_period, memo_structure, map_fyle_cards_netsuite_account, skip_cards_mapping, import_vendors_as_merchants, import_netsuite_employees, is_simplify_report_closure_enabled, import_items, name_in_journal_entry, allow_intercompany_vendors, je_single_credit_line) FROM stdin; -1 EXPENSE REPORT BILL 2021-11-15 08:56:07.193743+00 2021-11-15 08:56:07.193795+00 1 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f -2 JOURNAL ENTRY CREDIT CARD CHARGE 2021-11-16 04:18:15.836271+00 2021-11-16 04:20:09.969589+00 2 f f f \N f f f EMPLOYEE t f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f -3 JOURNAL ENTRY CREDIT CARD CHARGE 2021-12-03 11:04:00.194287+00 2021-12-03 11:04:00.1943+00 49 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f +COPY public.configurations (id, reimbursable_expenses_object, corporate_credit_card_expenses_object, created_at, updated_at, workspace_id, sync_fyle_to_netsuite_payments, sync_netsuite_to_fyle_payments, import_projects, auto_map_employees, import_categories, auto_create_destination_entity, auto_create_merchants, employee_field_mapping, import_tax_items, change_accounting_period, memo_structure, map_fyle_cards_netsuite_account, skip_cards_mapping, import_vendors_as_merchants, import_netsuite_employees, is_simplify_report_closure_enabled, import_items, name_in_journal_entry, allow_intercompany_vendors, je_single_credit_line, is_attachment_upload_enabled) FROM stdin; +1 EXPENSE REPORT BILL 2021-11-15 08:56:07.193743+00 2021-11-15 08:56:07.193795+00 1 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f t +2 JOURNAL ENTRY CREDIT CARD CHARGE 2021-11-16 04:18:15.836271+00 2021-11-16 04:20:09.969589+00 2 f f f \N f f f EMPLOYEE t f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f t +3 JOURNAL ENTRY CREDIT CARD CHARGE 2021-12-03 11:04:00.194287+00 2021-12-03 11:04:00.1943+00 49 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f t \. @@ -7997,6 +7998,8 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 204 workspaces 0040_alter_configuration_change_accounting_period 2024-11-18 04:28:36.094429+00 205 fyle 0035_support_split_expense_grouping 2024-11-22 10:40:59.441051+00 206 fyle 0036_expense_masked_corporate_card_number 2024-11-26 09:24:50.240658+00 +207 fyle_accounting_mappings 0027_alter_employeemapping_source_employee 2024-12-18 05:34:34.929303+00 +208 workspaces 0041_configuration_is_attachment_upload_enabled 2024-12-18 05:34:34.968096+00 \. @@ -11908,7 +11911,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 47, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 206, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 208, true); -- @@ -12396,6 +12399,14 @@ ALTER TABLE ONLY public.employee_mappings ADD CONSTRAINT employee_mappings_pkey PRIMARY KEY (id); +-- +-- Name: employee_mappings employee_mappings_source_employee_id_dd9948ba_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.employee_mappings + ADD CONSTRAINT employee_mappings_source_employee_id_dd9948ba_uniq UNIQUE (source_employee_id); + + -- -- Name: errors errors_expense_attribute_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -13054,13 +13065,6 @@ CREATE INDEX employee_mappings_destination_employee_id_b6764819 ON public.employ CREATE INDEX employee_mappings_destination_vendor_id_c4bd73df ON public.employee_mappings USING btree (destination_vendor_id); --- --- Name: employee_mappings_source_employee_id_dd9948ba; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX employee_mappings_source_employee_id_dd9948ba ON public.employee_mappings USING btree (source_employee_id); - - -- -- Name: employee_mappings_workspace_id_4a25f8c9; Type: INDEX; Schema: public; Owner: postgres -- diff --git a/tests/test_workspaces/data.json b/tests/test_workspaces/data.json index 4d12ce45..eef63782 100644 --- a/tests/test_workspaces/data.json +++ b/tests/test_workspaces/data.json @@ -25,7 +25,8 @@ "is_simplify_report_closure_enabled": true, "name_in_journal_entry": "MERCHANT", "allow_intercompany_vendors": false, - "je_single_credit_line": false + "je_single_credit_line": false, + "is_attachment_upload_enabled": true }, "workspace": { "id":1,