Skip to content

Commit 31a22c7

Browse files
Ashutosh619-sudoAshutosh619-sudo
andauthored
Fix: Send source entity change for rest flow (#874)
* Feat: Exporting Location Value to the Source Entity Field * added tests * made changes * added change for Rest flow * added tests for rest and soap --------- Co-authored-by: Ashutosh619-sudo <ashutosh.s@fyle.com>
1 parent dddd4be commit 31a22c7

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

apps/sage_intacct/exports/journal_entries.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def construct_journal_entry_payload(
7171
expense_group=journal_entry.expense_group
7272
)
7373
if source_entity_id:
74-
journal_entry_payload['baselocation_no'] = source_entity_id
74+
journal_entry_payload['baseLocation'] = {
75+
'id': source_entity_id
76+
}
7577

7678
logger.info("| Payload for the journal entry report creation | Content : {{WORKSPACE_ID = {}, EXPENSE_GROUP_ID = {}, JOURNAL_ENTRY_PAYLOAD = {}}}".format(
7779
workspace_id, journal_entry.expense_group.id, journal_entry_payload

tests/test_sageintacct/test_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_get_source_entity_id_returns_none(db):
175175

176176
def test_construct_journal_entry_payload_with_source_entity(db, mocker, create_journal_entry):
177177
"""
178-
Test construct_journal_entry_payload includes baselocation_no when conditions are met
178+
Test construct_journal_entry_payload includes baseLocation when conditions are met
179179
"""
180180
workspace_id = 1
181181
journal_entry, journal_entry_lineitems = create_journal_entry
@@ -192,5 +192,5 @@ def test_construct_journal_entry_payload_with_source_entity(db, mocker, create_j
192192

193193
payload = construct_journal_entry_payload(workspace_id, journal_entry, journal_entry_lineitems)
194194

195-
assert 'baselocation_no' in payload
196-
assert payload['baselocation_no'] == 'LOC123'
195+
assert 'baseLocation' in payload
196+
assert payload['baseLocation']['id'] == 'LOC123'

tests/test_sageintacct/test_utils.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from fyle_accounting_mappings.models import CategoryMapping, DestinationAttribute, ExpenseAttribute, Mapping
88
from sageintacctsdk.exceptions import WrongParamsError
99

10-
from apps.mappings.models import GeneralMapping
10+
from apps.mappings.models import GeneralMapping, LocationEntityMapping
1111
from apps.sage_intacct.models import CostCode, CostType, SageIntacctAttributesCount
1212
from apps.sage_intacct.utils import Configuration, SageIntacctConnector, SageIntacctCredential, Workspace
1313
from fyle_intacct_api.utils import invalidate_sage_intacct_credentials
@@ -485,6 +485,36 @@ def test_construct_journal_entry(create_journal_entry, db):
485485
assert dict_compare_keys(journal_entry_object, data['journal_entry_re_payload']) == [], 'construct journal entry api return diffs in keys'
486486

487487

488+
def test_construct_journal_entry_with_baselocation(create_journal_entry, db):
489+
"""
490+
Test construct journal entry includes BASELOCATION_NO when conditions are met
491+
"""
492+
workspace_id = 1
493+
494+
intacct_credentials = SageIntacctCredential.objects.get(workspace_id=workspace_id)
495+
sage_intacct_connection = SageIntacctConnector(credentials_object=intacct_credentials, workspace_id=workspace_id)
496+
497+
LocationEntityMapping.objects.filter(workspace_id=workspace_id).update(destination_id='top_level')
498+
499+
configuration = Configuration.objects.get(workspace_id=workspace_id)
500+
configuration.je_single_credit_line = True
501+
configuration.save()
502+
503+
general_mappings = GeneralMapping.objects.get(workspace_id=workspace_id)
504+
general_mappings.default_location_id = 'LOC123'
505+
general_mappings.save()
506+
507+
journal_entry, journal_entry_lineitems = create_journal_entry
508+
509+
journal_entry_object = sage_intacct_connection._SageIntacctConnector__construct_journal_entry(
510+
journal_entry=journal_entry,
511+
journal_entry_lineitems=journal_entry_lineitems
512+
)
513+
514+
assert 'BASELOCATION_NO' in journal_entry_object
515+
assert journal_entry_object['BASELOCATION_NO'] == 'LOC123'
516+
517+
488518
def test_construct_sage_intacct_reimbursement(create_sage_intacct_reimbursement, db):
489519
"""
490520
Test construct sage intacct reimbursement

0 commit comments

Comments
 (0)