Skip to content

Commit

Permalink
feat: Allow intercompany vendors (#460)
Browse files Browse the repository at this point in the history
* feat: Allow intercompany vendors

* Fixing correct condition

* Updating sql fixuture for tests

* Fixing tests
  • Loading branch information
Shwetabhk authored Nov 28, 2023
1 parent 125a594 commit 512a6c8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
8 changes: 7 additions & 1 deletion apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
1 change: 1 addition & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 9 additions & 7 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);


Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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);


--
Expand Down
3 changes: 2 additions & 1 deletion tests/test_workspaces/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 512a6c8

Please sign in to comment.