Skip to content

Commit

Permalink
test: deduplicate gain/loss JE on reconciling journals against inv
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Sep 2, 2023
1 parent 79c6f01 commit cb6da6e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions erpnext/controllers/tests/test_accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,51 @@ def test_23_same_journal_split_against_single_invoice(self):
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_je, [])

def test_24_journal_against_multiple_invoices(self):
si1 = self.create_sales_invoice(qty=1, conversion_rate=80, rate=1)
si2 = self.create_sales_invoice(qty=1, conversion_rate=80, rate=1)

# Payment
je = self.create_journal_entry(
acc1=self.debit_usd,
acc1_exc_rate=75,
acc2=self.cash,
acc1_amount=-2,
acc2_amount=-150,
acc2_exc_rate=1,
)
je.accounts[0].party_type = "Customer"
je.accounts[0].party = self.customer
je = je.save().submit()

pr = self.create_payment_reconciliation()
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 2)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
pr.reconcile()
self.assertEqual(len(pr.invoices), 0)
self.assertEqual(len(pr.payments), 0)

si1.reload()
si2.reload()

self.assertEqual(si1.outstanding_amount, 0)
self.assertEqual(si2.outstanding_amount, 0)
self.assert_ledger_outstanding(si1.doctype, si1.name, 0.0, 0.0)
self.assert_ledger_outstanding(si2.doctype, si2.name, 0.0, 0.0)

# Exchange Gain/Loss Journal should've been cancelled
# remove payment JE from list
exc_je_for_si1 = [x for x in self.get_journals_for(si1.doctype, si1.name) if x.parent != je.name]
exc_je_for_si2 = [x for x in self.get_journals_for(si2.doctype, si2.name) if x.parent != je.name]
exc_je_for_je = [x for x in self.get_journals_for(je.doctype, je.name) if x.parent != je.name]
self.assertEqual(len(exc_je_for_si1), 1)
self.assertEqual(len(exc_je_for_si2), 1)
self.assertEqual(len(exc_je_for_je), 2)

def test_30_cr_note_against_sales_invoice(self):
"""
Reconciling Cr Note against Sales Invoice, both having different exchange rates
Expand Down

0 comments on commit cb6da6e

Please sign in to comment.