Skip to content

Commit

Permalink
add support for class department on bill top level (#502)
Browse files Browse the repository at this point in the history
* add support for class department on bill top level

* Fixing a small thing in SQL fixture

* Fix Tests

---------

Co-authored-by: Shwetabh Kumar <[email protected]>
  • Loading branch information
ruuushhh and Shwetabhk authored Mar 1, 2024
1 parent bc7346c commit 538e1fc
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 10 deletions.
28 changes: 28 additions & 0 deletions apps/mappings/migrations/0013_auto_20240229_0804.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.14 on 2024-02-29 08:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mappings', '0012_generalmapping_override_tax_details'),
]

operations = [
migrations.AddField(
model_name='generalmapping',
name='class_id',
field=models.CharField(help_text='NetSuite Class id', max_length=255, null=True),
),
migrations.AddField(
model_name='generalmapping',
name='class_level',
field=models.CharField(help_text='Transaction Body, Line, Both', max_length=255, null=True),
),
migrations.AddField(
model_name='generalmapping',
name='class_name',
field=models.CharField(help_text='NetSuite Class name', max_length=255, null=True),
),
]
4 changes: 4 additions & 0 deletions apps/mappings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class GeneralMapping(models.Model):
department_id = models.CharField(max_length=255, help_text='NetSuite Department id', null=True)
department_level = models.CharField(max_length=255, help_text='Transaction Body, Line, Both', null=True)

class_name = models.CharField(max_length=255, help_text='NetSuite Class name', null=True)
class_id = models.CharField(max_length=255, help_text='NetSuite Class id', null=True)
class_level = models.CharField(max_length=255, help_text='Transaction Body, Line, Both', null=True)

vendor_payment_account_id = models.CharField(
max_length=255, help_text='NetSuite VendorPayment Account id', null=True)
vendor_payment_account_name = models.CharField(max_length=255, help_text='VendorPayment Account name', null=True)
Expand Down
9 changes: 9 additions & 0 deletions apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,12 @@ def __construct_bill(self, bill: Bill, bill_lineitems: List[BillLineitem]) -> Di
'externalId': None,
'type': 'department'
},
'class': {
'name': None,
'internalId': bill.class_id,
'externalId': None,
'type': 'classification'
},
'approvalStatus': None,
'nextApprover': None,
'vatRegNum': None,
Expand Down Expand Up @@ -1371,6 +1377,9 @@ def __construct_credit_card_charge(
'department': {
'internalId': credit_card_charge.department_id
},
'class': {
'internalId': credit_card_charge.class_id
},
'tranDate': transaction_date,
'memo': credit_card_charge.memo,
'tranid': credit_card_charge.reference_number,
Expand Down
23 changes: 23 additions & 0 deletions apps/netsuite/migrations/0025_auto_20240229_0804.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.14 on 2024-02-29 08:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('netsuite', '0024_bill_override_tax_details'),
]

operations = [
migrations.AddField(
model_name='bill',
name='class_id',
field=models.CharField(help_text='NetSuite Class id', max_length=255, null=True),
),
migrations.AddField(
model_name='creditcardcharge',
name='class_id',
field=models.CharField(help_text='NetSuite Class id', max_length=255, null=True),
),
]
6 changes: 6 additions & 0 deletions apps/netsuite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class Bill(models.Model):
entity_id = models.CharField(max_length=255, help_text='NetSuite vendor id')
subsidiary_id = models.CharField(max_length=255, help_text='NetSuite subsidiary id')
department_id = models.CharField(max_length=255, help_text='NetSuite department id', null=True)
class_id = models.CharField(max_length=255, help_text='NetSuite Class id', null=True)
location_id = models.CharField(max_length=255, help_text='NetSuite Location id', null=True)
currency = models.CharField(max_length=255, help_text='Bill Currency')
memo = models.TextField(help_text='Bill Description')
Expand Down Expand Up @@ -384,6 +385,8 @@ def create_bill(expense_group: ExpenseGroup):
'entity_id': vendor_id,
'department_id': general_mappings.department_id if general_mappings.department_level in [
'TRANSACTION_BODY', 'ALL'] else None,
'class_id': general_mappings.class_id if general_mappings.class_level in [
'TRANSACTION_BODY', 'ALL'] else None,
'location_id': general_mappings.location_id if general_mappings.location_level in [
'TRANSACTION_BODY', 'ALL'] else None,
'memo': 'Reimbursable expenses by {0}'.format(description.get('employee_email')) if
Expand Down Expand Up @@ -536,6 +539,7 @@ class CreditCardCharge(models.Model):
credit_card_account_id = models.CharField(max_length=255, help_text='NetSuite Accounts Payable Account id')
entity_id = models.CharField(max_length=255, help_text='NetSuite vendor id')
department_id = models.CharField(max_length=255, help_text='NetSuite department id', null=True)
class_id = models.CharField(max_length=255, help_text='NetSuite Class id', null=True)
subsidiary_id = models.CharField(max_length=255, help_text='NetSuite subsidiary id')
location_id = models.CharField(max_length=255, help_text='NetSuite Location id', null=True)
currency = models.CharField(max_length=255, help_text='CC Charge Currency')
Expand Down Expand Up @@ -599,6 +603,8 @@ def create_credit_card_charge(expense_group: ExpenseGroup):
'subsidiary_id': subsidiary_mappings.internal_id,
'credit_card_account_id': ccc_account_id,
'department_id': department_id,
'class_id': general_mappings.class_id if general_mappings.class_level in [
'TRANSACTION_BODY', 'ALL'] else None,
'entity_id': vendor_id,
'location_id': general_mappings.location_id if general_mappings.location_level in [
'TRANSACTION_BODY', 'ALL'] else None,
Expand Down
27 changes: 17 additions & 10 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ CREATE TABLE public.bills (
paid_on_netsuite boolean NOT NULL,
reference_number character varying(255),
department_id character varying(255),
override_tax_details boolean NOT NULL
override_tax_details boolean NOT NULL,
class_id character varying(255)
);


Expand Down Expand Up @@ -391,7 +392,8 @@ CREATE TABLE public.credit_card_charges (
updated_at timestamp with time zone NOT NULL,
expense_group_id integer NOT NULL,
reference_number character varying(255),
department_id character varying(255)
department_id character varying(255),
class_id character varying(255)
);


Expand Down Expand Up @@ -1384,7 +1386,10 @@ CREATE TABLE public.general_mappings (
use_employee_location boolean NOT NULL,
department_id character varying(255),
department_name character varying(255),
override_tax_details boolean NOT NULL
override_tax_details boolean NOT NULL,
class_id character varying(255),
class_level character varying(255),
class_name character varying(255)
);


Expand Down Expand Up @@ -2551,7 +2556,7 @@ COPY public.bill_lineitems (id, account_id, location_id, department_id, class_id
-- Data for Name: bills; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.bills (id, entity_id, accounts_payable_id, subsidiary_id, location_id, currency, memo, external_id, created_at, updated_at, expense_group_id, transaction_date, payment_synced, paid_on_netsuite, reference_number, department_id, override_tax_details) FROM stdin;
COPY public.bills (id, entity_id, accounts_payable_id, subsidiary_id, location_id, currency, memo, external_id, created_at, updated_at, expense_group_id, transaction_date, payment_synced, paid_on_netsuite, reference_number, department_id, override_tax_details, class_id) FROM stdin;
\.


Expand Down Expand Up @@ -2591,7 +2596,7 @@ COPY public.credit_card_charge_lineitems (id, account_id, location_id, departmen
-- Data for Name: credit_card_charges; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.credit_card_charges (id, credit_card_account_id, entity_id, subsidiary_id, location_id, currency, memo, external_id, transaction_date, created_at, updated_at, expense_group_id, reference_number, department_id) FROM stdin;
COPY public.credit_card_charges (id, credit_card_account_id, entity_id, subsidiary_id, location_id, currency, memo, external_id, transaction_date, created_at, updated_at, expense_group_id, reference_number, department_id, class_id) FROM stdin;
\.


Expand Down Expand Up @@ -7848,6 +7853,8 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
182 fyle 0030_auto_20240208_1206 2024-02-08 12:26:48.026661+00
183 mappings 0012_generalmapping_override_tax_details 2024-02-23 09:02:00.114563+00
184 netsuite 0024_bill_override_tax_details 2024-02-23 09:02:00.124562+00
185 mappings 0013_auto_20240229_0804 2024-02-29 10:14:58.836562+00
186 netsuite 0025_auto_20240229_0804 2024-02-29 10:14:58.850038+00
\.


Expand Down Expand Up @@ -11505,10 +11512,10 @@ COPY public.fyle_credentials (id, refresh_token, created_at, updated_at, workspa
-- Data for Name: general_mappings; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.general_mappings (id, location_name, location_id, accounts_payable_name, accounts_payable_id, created_at, updated_at, workspace_id, default_ccc_account_id, default_ccc_account_name, reimbursable_account_id, reimbursable_account_name, default_ccc_vendor_id, default_ccc_vendor_name, vendor_payment_account_id, vendor_payment_account_name, location_level, department_level, use_employee_department, use_employee_class, use_employee_location, department_id, department_name, override_tax_details) FROM stdin;
1 hubajuba 8 Accounts Payable 25 2021-11-15 08:56:31.432106+00 2021-11-15 13:21:26.113427+00 1 \N \N 118 Unapproved Expense Reports 1674 Ashwin Vendor \N \N TRANSACTION_BODY \N f f f \N \N f
2 \N \N Accounts Payable 25 2021-11-16 04:18:39.195287+00 2021-11-16 04:18:39.195312+00 2 228 Aus Account 118 Unapproved Expense Reports 12104 Nilesh Aus Vendor \N \N \N \N f f f \N \N f
3 hukiju 10 \N \N 2021-12-03 11:24:17.962764+00 2021-12-03 11:24:17.962809+00 49 228 Aus Account 228 Aus Account 12104 Nilesh Aus Vendor \N \N TRANSACTION_BODY \N f f f \N \N f
COPY public.general_mappings (id, location_name, location_id, accounts_payable_name, accounts_payable_id, created_at, updated_at, workspace_id, default_ccc_account_id, default_ccc_account_name, reimbursable_account_id, reimbursable_account_name, default_ccc_vendor_id, default_ccc_vendor_name, vendor_payment_account_id, vendor_payment_account_name, location_level, department_level, use_employee_department, use_employee_class, use_employee_location, department_id, department_name, override_tax_details, class_id, class_level, class_name) FROM stdin;
1 hubajuba 8 Accounts Payable 25 2021-11-15 08:56:31.432106+00 2021-11-15 13:21:26.113427+00 1 \N \N 118 Unapproved Expense Reports 1674 Ashwin Vendor \N \N TRANSACTION_BODY \N f f f \N \N f \N \N \N
2 \N \N Accounts Payable 25 2021-11-16 04:18:39.195287+00 2021-11-16 04:18:39.195312+00 2 228 Aus Account 118 Unapproved Expense Reports 12104 Nilesh Aus Vendor \N \N \N \N f f f \N \N f \N \N \N
3 hukiju 10 \N \N 2021-12-03 11:24:17.962764+00 2021-12-03 11:24:17.962809+00 49 228 Aus Account 228 Aus Account 12104 Nilesh Aus Vendor \N \N TRANSACTION_BODY \N f f f \N \N f \N \N \N
\.


Expand Down Expand Up @@ -11743,7 +11750,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', 181, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 186, true);


--
Expand Down
19 changes: 19 additions & 0 deletions tests/test_netsuite/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
'externalId': None,
'type': 'department'
},
'class': {
'name': None,
'internalId': None,
'externalId': None,
'type': 'classification'
},
"approvalStatus": None,
"nextApprover": None,
"vatRegNum": None,
Expand Down Expand Up @@ -313,6 +319,12 @@
'externalId': None,
'type': 'department'
},
'class': {
'name': None,
'internalId': None,
'externalId': None,
'type': 'classification'
},
"approvalStatus": None,
"nextApprover": None,
"vatRegNum": None,
Expand Down Expand Up @@ -465,6 +477,12 @@
'externalId': None,
'type': 'department'
},
'class': {
'name': None,
'internalId': None,
'externalId': None,
'type': 'classification'
},
"approvalStatus": None,
"nextApprover": None,
"vatRegNum": None,
Expand Down Expand Up @@ -1021,6 +1039,7 @@
'location': {'internalId': '10'},
'currency': {'internalId': '1'},
'department': {'internalId': None},
'class': {'internalId': None},
'tranDate': '12/03/2021',
'memo': 'Credit card expenses by [email protected]',
'tranid':'CR/27/B/8',
Expand Down

0 comments on commit 538e1fc

Please sign in to comment.