From 9b448275a6280eae296234d8af23a11094528360 Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Fri, 11 Oct 2024 19:20:59 +0530 Subject: [PATCH 1/4] test: add tests for single credit line <> JE --- tests/sql_fixtures/reset_db_fixtures/reset_db.sql | 14 ++++++++------ tests/test_workspaces/data.json | 3 ++- .../test_apis/test_advanced_settings/fixtures.py | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index f439d119..f899ec84 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -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 ); @@ -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 \. @@ -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 \. @@ -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); -- diff --git a/tests/test_workspaces/data.json b/tests/test_workspaces/data.json index 062f1739..4d12ce45 100644 --- a/tests/test_workspaces/data.json +++ b/tests/test_workspaces/data.json @@ -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, diff --git a/tests/test_workspaces/test_apis/test_advanced_settings/fixtures.py b/tests/test_workspaces/test_apis/test_advanced_settings/fixtures.py index 34660b53..a0c7d8b9 100644 --- a/tests/test_workspaces/test_apis/test_advanced_settings/fixtures.py +++ b/tests/test_workspaces/test_apis/test_advanced_settings/fixtures.py @@ -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": { @@ -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": { From e5312e792b25c7c453840051b1658ffdb427a278 Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Fri, 11 Oct 2024 20:22:30 +0530 Subject: [PATCH 2/4] test: add tests --- apps/netsuite/connector.py | 5 ++- tests/test_netsuite/fixtures.py | 58 +++++++++++++++++++++++- tests/test_netsuite/test_connector.py | 65 ++++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 4 deletions(-) diff --git a/apps/netsuite/connector.py b/apps/netsuite/connector.py index e3ec74eb..dd24a70b 100644 --- a/apps/netsuite/connector.py +++ b/apps/netsuite/connector.py @@ -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 @@ -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) diff --git a/tests/test_netsuite/fixtures.py b/tests/test_netsuite/fixtures.py index 79449799..48c55603 100644 --- a/tests/test_netsuite/fixtures.py +++ b/tests/test_netsuite/fixtures.py @@ -1053,8 +1053,64 @@ 'tranDate': '2021-12-08T10:33:44', 'tranId': None, 'externalId': 'journal 47 - admin1@fyleforintacct.in', - } + }, ], + '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 Credit 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'}, diff --git a/tests/test_netsuite/test_connector.py b/tests/test_netsuite/test_connector.py index fb5edf17..74726334 100644 --- a/tests/test_netsuite/test_connector.py +++ b/tests/test_netsuite/test_connector.py @@ -1,4 +1,5 @@ import pytest +from copy import deepcopy from datetime import datetime from unittest import mock from apps.fyle.models import ExpenseGroup @@ -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): From f3a6b16e66244a4a8bb07b442b25c8ba36c39e30 Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Mon, 14 Oct 2024 17:52:44 +0530 Subject: [PATCH 3/4] API fix --- apps/workspaces/apis/advanced_settings/serializers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/workspaces/apis/advanced_settings/serializers.py b/apps/workspaces/apis/advanced_settings/serializers.py index b0e225d6..8617f461 100644 --- a/apps/workspaces/apis/advanced_settings/serializers.py +++ b/apps/workspaces/apis/advanced_settings/serializers.py @@ -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') } ) From 2398ccbbcb7df93203d6f26e15003e3a57e534d8 Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Wed, 16 Oct 2024 18:24:47 +0530 Subject: [PATCH 4/4] fix memo --- apps/netsuite/connector.py | 2 +- tests/test_netsuite/fixtures.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/netsuite/connector.py b/apps/netsuite/connector.py index dd24a70b..64d623be 100644 --- a/apps/netsuite/connector.py +++ b/apps/netsuite/connector.py @@ -2148,7 +2148,7 @@ def __construct_single_itemized_credit_line(journal_entry_lineitems: List[Journa 'line': None, 'lineTaxCode': None, 'lineTaxRate': None, - 'memo': 'Total Credit Amount', + 'memo': 'Total Amount', 'residual': None, 'revenueRecognitionRule': None, 'schedule': None, diff --git a/tests/test_netsuite/fixtures.py b/tests/test_netsuite/fixtures.py index 48c55603..566486c6 100644 --- a/tests/test_netsuite/fixtures.py +++ b/tests/test_netsuite/fixtures.py @@ -1097,7 +1097,7 @@ 'line': None, 'lineTaxCode': None, 'lineTaxRate': None, - 'memo': 'Total Credit Amount', + 'memo': 'Total Amount', 'residual': None, 'revenueRecognitionRule': None, 'schedule': None,