Skip to content

Commit

Permalink
test: add tests for single credit line <> JE (#656)
Browse files Browse the repository at this point in the history
* test: add tests for single credit line <> JE

* test: add tests

* API fix

* fix memo
  • Loading branch information
ashwin1111 authored Oct 16, 2024
1 parent 885678a commit 1e38d5f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 13 deletions.
7 changes: 4 additions & 3 deletions apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@ def construct_journal_entry_lineitems(self, journal_entry_lineitems: List[Journa

return lines

def construct_single_itemized_credit_line(self, journal_entry_lineitems: List[JournalEntryLineItem]):
@staticmethod
def __construct_single_itemized_credit_line(journal_entry_lineitems: List[JournalEntryLineItem]):
"""
Create journal entry line items for single credit line
:return: constructed line items
Expand Down Expand Up @@ -2147,7 +2148,7 @@ def construct_single_itemized_credit_line(self, journal_entry_lineitems: List[Jo
'line': None,
'lineTaxCode': None,
'lineTaxRate': None,
'memo': 'Total Credit Amount',
'memo': 'Total Amount',
'residual': None,
'revenueRecognitionRule': None,
'schedule': None,
Expand Down Expand Up @@ -2178,7 +2179,7 @@ def __construct_journal_entry(self, journal_entry: JournalEntry,
org_id = Workspace.objects.get(id=journal_entry.expense_group.workspace_id).fyle_org_id

if configuration.je_single_credit_line:
credit_line = self.construct_single_itemized_credit_line(journal_entry_lineitems)
credit_line = self.__construct_single_itemized_credit_line(journal_entry_lineitems)
else:
credit_line = self.construct_journal_entry_lineitems(journal_entry_lineitems, credit='Credit', org_id=org_id)

Expand Down
3 changes: 2 additions & 1 deletion apps/workspaces/apis/advanced_settings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def update(self, instance, validated):
'auto_create_destination_entity': configurations.get('auto_create_destination_entity'),
'auto_create_merchants': configurations.get('auto_create_merchants'),
'change_accounting_period': configurations.get('change_accounting_period'),
'memo_structure': configurations.get('memo_structure')
'memo_structure': configurations.get('memo_structure'),
'je_single_credit_line': configurations.get('je_single_credit_line')
}
)

Expand Down
14 changes: 8 additions & 6 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ CREATE TABLE public.configurations (
is_simplify_report_closure_enabled boolean NOT NULL,
import_items boolean NOT NULL,
name_in_journal_entry character varying(100) NOT NULL,
allow_intercompany_vendors boolean NOT NULL
allow_intercompany_vendors boolean NOT NULL,
je_single_credit_line boolean NOT NULL
);


Expand Down Expand Up @@ -2691,10 +2692,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) 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
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
\.


Expand Down Expand Up @@ -7984,6 +7985,7 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
197 netsuite 0026_auto_20240902_1650 2024-09-02 16:50:55.770274+00
198 netsuite 0027_auto_20240924_0820 2024-09-24 08:24:35.223017+00
199 fyle_accounting_mappings 0026_destinationattribute_code 2024-10-01 08:54:06.770864+00
200 workspaces 0039_configuration_je_single_credit_line 2024-10-11 13:43:49.169823+00
\.


Expand Down Expand Up @@ -11895,7 +11897,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', 199, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 200, true);


--
Expand Down
58 changes: 57 additions & 1 deletion tests/test_netsuite/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,64 @@
'tranDate': '2021-12-08T10:33:44',
'tranId': None,
'externalId': 'journal 47 - [email protected]',
}
},
],
'journal_entry_clubbed_lines': [{
'account': {
'name': None,
'internalId': '228',
'externalId': None,
'type': 'account',
},
'department': {
'name': None,
'internalId': None,
'externalId': None,
'type': 'department',
},
'location': {
'name': None,
'internalId': None,
'externalId': None,
'type': 'location',
},
'class': {
'name': None,
'internalId': None,
'externalId': None,
'type': 'classification',
},
'entity': {
'name': None,
'internalId': '10491',
'externalId': None,
'type': 'vendor',
},
'credit': 120.0,
'creditTax': None,
'customFieldList': [],
'debit': None,
'debitTax': None,
'eliminate': None,
'endDate': None,
'grossAmt': None,
'line': None,
'lineTaxCode': None,
'lineTaxRate': None,
'memo': 'Total Amount',
'residual': None,
'revenueRecognitionRule': None,
'schedule': None,
'scheduleNum': None,
'startDate': None,
'tax1Acct': None,
'taxAccount': None,
'taxBasis': None,
'tax1Amt': None,
'taxCode': None,
'taxRate1': None,
'totalAmount': None,
}],
'credit_card_charge': [
{
'account': {'internalId': '228'},
Expand Down
65 changes: 64 additions & 1 deletion tests/test_netsuite/test_connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from copy import deepcopy
from datetime import datetime
from unittest import mock
from apps.fyle.models import ExpenseGroup
Expand Down Expand Up @@ -71,7 +72,69 @@ def test_construct_journal_entry(create_journal_entry):

journal_entry_object['tranDate'] = data['journal_entry_without_single_line'][0]['tranDate']

assert journal_entry_object == data['journal_entry_without_single_line'][0]
assert journal_entry_object == data['journal_entry_without_single_line'][0]

configuration.je_single_credit_line = True
configuration.save()

journal_entry_object = netsuite_connection._NetSuiteConnector__construct_journal_entry(journal_entry, journal_entry_lineitem, configuration)

# With flag being different, the output should be different
assert journal_entry_object != data['journal_entry_without_single_line'][0]


def test_construct_single_itemized_credit_line(create_journal_entry):
netsuite_credentials = NetSuiteCredentials.objects.get(workspace_id=1)
netsuite_connection = NetSuiteConnector(
netsuite_credentials=netsuite_credentials, workspace_id=1
)

_, journal_entry_lineitems = create_journal_entry

# Single line item
constructed_lines = netsuite_connection._NetSuiteConnector__construct_single_itemized_credit_line(
journal_entry_lineitems
)
assert constructed_lines == data['journal_entry_clubbed_lines']

# Double line item with same ids
journal_entry_lineitems_2 = journal_entry_lineitems.copy() + journal_entry_lineitems.copy()
constructed_lines = netsuite_connection._NetSuiteConnector__construct_single_itemized_credit_line(
journal_entry_lineitems_2
)

expected_lines = deepcopy(data['journal_entry_clubbed_lines'][0])
expected_lines['credit'] = 2 * expected_lines['credit']
expected_lines = [expected_lines]

assert constructed_lines == expected_lines

# Multiple line items with different ids
journal_entry_lineitems_3 = []
for i in range(4):
instance = deepcopy(journal_entry_lineitems[0])
instance.id = None
journal_entry_lineitems_3.append(instance)

journal_entry_lineitems_3[1].entity_id = '111'
journal_entry_lineitems_3[2].debit_account_id = '222'

constructed_lines = netsuite_connection._NetSuiteConnector__construct_single_itemized_credit_line(
journal_entry_lineitems_3
)

line_1 = deepcopy(data['journal_entry_clubbed_lines'][0])
line_2 = deepcopy(data['journal_entry_clubbed_lines'][0])
line_3 = deepcopy(data['journal_entry_clubbed_lines'][0])

line_2['entity']['internalId'] = '111'
line_3['account']['internalId'] = '222'

line_1['credit'] = 2 * line_1['credit']

expected_lines = [line_1, line_2, line_3]

assert constructed_lines == expected_lines


def test_contruct_credit_card_charge(create_credit_card_charge):
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 @@ -24,7 +24,8 @@
"import_netsuite_employees": true,
"is_simplify_report_closure_enabled": true,
"name_in_journal_entry": "MERCHANT",
"allow_intercompany_vendors": false
"allow_intercompany_vendors": false,
"je_single_credit_line": false
},
"workspace": {
"id":1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"auto_create_destination_entity": False,
"auto_create_merchants": True,
"memo_structure": ["merchant", "purpose"],
"je_single_credit_line": False,
},
"general_mappings": {
"vendor_payment_account": {
Expand Down Expand Up @@ -47,6 +48,7 @@
"auto_create_destination_entity": False,
"auto_create_merchants": True,
"memo_structure": ["merchant", "purpose"],
"je_single_credit_line": False,
},
"general_mappings": {
"vendor_payment_account": {
Expand Down

0 comments on commit 1e38d5f

Please sign in to comment.