diff --git a/apps/netsuite/connector.py b/apps/netsuite/connector.py index 38171c8e..677b7f0a 100644 --- a/apps/netsuite/connector.py +++ b/apps/netsuite/connector.py @@ -536,6 +536,12 @@ def sync_vendors(self): Sync vendors """ subsidiary_mapping = SubsidiaryMapping.objects.get(workspace_id=self.workspace_id) + configuration = Configuration.objects.filter(workspace_id=self.workspace_id).first() + if not configuration: + configuration = Configuration( + workspace_id=self.workspace_id, + allow_intercompany_vendors=False + ) vendors_generator = self.connection.vendors.get_all_generator() @@ -546,7 +552,7 @@ def sync_vendors(self): 'email': vendor['email'] if vendor['email'] else None } if 'subsidiary' in vendor and vendor['subsidiary']: - if vendor['subsidiary']['internalId'] == subsidiary_mapping.internal_id: + if vendor['subsidiary']['internalId'] == subsidiary_mapping.internal_id or configuration.allow_intercompany_vendors: attributes.append({ 'attribute_type': 'VENDOR', 'display_name': 'Vendor', diff --git a/apps/workspaces/migrations/0038_configuration_allow_intercompany_vendors.py b/apps/workspaces/migrations/0038_configuration_allow_intercompany_vendors.py new file mode 100644 index 00000000..40885a12 --- /dev/null +++ b/apps/workspaces/migrations/0038_configuration_allow_intercompany_vendors.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.14 on 2023-11-28 10:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0037_lastexportdetail'), + ] + + operations = [ + migrations.AddField( + model_name='configuration', + name='allow_intercompany_vendors', + field=models.BooleanField(default=False, help_text='Allow intercompany vendors'), + ), + ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 7c788dc4..2440127b 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -179,6 +179,7 @@ class Configuration(models.Model): created_at = models.DateTimeField(auto_now_add=True, help_text='Created at') updated_at = models.DateTimeField(auto_now=True, help_text='Updated at') 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') 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 4742df84..dcac805b 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -2,7 +2,7 @@ -- PostgreSQL database dump -- --- Dumped from database version 15.2 (Debian 15.2-1.pgdg110+1) +-- Dumped from database version 15.4 (Debian 15.4-2.pgdg120+1) -- Dumped by pg_dump version 15.5 (Debian 15.5-1.pgdg120+1) SET statement_timeout = 0; @@ -317,7 +317,8 @@ CREATE TABLE public.configurations ( import_netsuite_employees boolean NOT NULL, is_simplify_report_closure_enabled boolean NOT NULL, import_items boolean NOT NULL, - name_in_journal_entry character varying(100) NOT NULL + name_in_journal_entry character varying(100) NOT NULL, + allow_intercompany_vendors boolean NOT NULL ); @@ -2562,10 +2563,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) 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 -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 -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 +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) 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 +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 +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 \. @@ -7828,6 +7829,7 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 172 workspaces 0036_auto_20231027_0709 2023-11-20 12:12:44.910371+00 173 tasks 0009_error 2023-11-20 12:12:44.97278+00 174 workspaces 0037_lastexportdetail 2023-11-20 12:12:45.043763+00 +175 workspaces 0038_configuration_allow_intercompany_vendors 2023-11-28 10:23:29.709496+00 \. @@ -11723,7 +11725,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 45, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 174, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 175, true); -- diff --git a/tests/test_workspaces/data.json b/tests/test_workspaces/data.json index c6453215..062f1739 100644 --- a/tests/test_workspaces/data.json +++ b/tests/test_workspaces/data.json @@ -23,7 +23,8 @@ "updated_at":"2021-11-10T20:19:39.312105Z", "import_netsuite_employees": true, "is_simplify_report_closure_enabled": true, - "name_in_journal_entry": "MERCHANT" + "name_in_journal_entry": "MERCHANT", + "allow_intercompany_vendors": false }, "workspace": { "id":1,