From bb8ac94adcf8b804bf04dfd9eb71057e87189c61 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 20 Sep 2023 09:36:18 +0530 Subject: [PATCH] test: assert ledger entries on partial reconciliation with `Advance as Liability`, partial reconciliation should not post duplicate ledger entries for same reference (cherry picked from commit 3263f2023c0a6ceabfbdd1eeb5202843d4532b76) --- .../purchase_invoice/test_purchase_invoice.py | 4 +- .../sales_invoice/test_sales_invoice.py | 95 ++++++++++++++++++- 2 files changed, 93 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 171cc0ccdf..322fc9f16b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -1769,10 +1769,10 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin): # Check GL Entry against payment doctype expected_gle = [ - ["Advances Paid - _TC", 0.0, 500, nowdate()], + ["Advances Paid - _TC", 500.0, 0.0, nowdate()], + ["Advances Paid - _TC", 0.0, 500.0, nowdate()], ["Cash - _TC", 0.0, 500, nowdate()], ["Creditors - _TC", 500, 0.0, nowdate()], - ["Creditors - _TC", 500, 0.0, nowdate()], ] check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry") diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index e8a53f8819..36b4a91912 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3377,21 +3377,21 @@ class TestSalesInvoice(FrappeTestCase): def test_advance_entries_as_liability(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry - account = create_account( + advance_account = create_account( parent_account="Current Liabilities - _TC", account_name="Advances Received", company="_Test Company", account_type="Receivable", ) - set_advance_flag(company="_Test Company", flag=1, default_account=account) + set_advance_flag(company="_Test Company", flag=1, default_account=advance_account) pe = create_payment_entry( company="_Test Company", payment_type="Receive", party_type="Customer", party="_Test Customer", - paid_from="Debtors - _TC", + paid_from=advance_account, paid_to="Cash - _TC", paid_amount=1000, ) @@ -3417,9 +3417,9 @@ class TestSalesInvoice(FrappeTestCase): # Check GL Entry against payment doctype expected_gle = [ + ["Advances Received - _TC", 0.0, 1000.0, nowdate()], ["Advances Received - _TC", 500, 0.0, nowdate()], ["Cash - _TC", 1000, 0.0, nowdate()], - ["Debtors - _TC", 0.0, 1000, nowdate()], ["Debtors - _TC", 0.0, 500, nowdate()], ] @@ -3456,6 +3456,93 @@ class TestSalesInvoice(FrappeTestCase): si.items[0].rate = 10 si.save() + def test_partial_allocation_on_advance_as_liability(self): + from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry + + company = "_Test Company" + customer = "_Test Customer" + debtors_acc = "Debtors - _TC" + advance_account = create_account( + parent_account="Current Liabilities - _TC", + account_name="Advances Received", + company="_Test Company", + account_type="Receivable", + ) + + set_advance_flag(company="_Test Company", flag=1, default_account=advance_account) + + pe = create_payment_entry( + company=company, + payment_type="Receive", + party_type="Customer", + party=customer, + paid_from=advance_account, + paid_to="Cash - _TC", + paid_amount=1000, + ) + pe.submit() + + si = create_sales_invoice( + company=company, + customer=customer, + do_not_save=True, + do_not_submit=True, + rate=1000, + price_list_rate=1000, + ) + si.base_grand_total = 1000 + si.grand_total = 1000 + si.set_advances() + for advance in si.advances: + advance.allocated_amount = 200 if advance.reference_name == pe.name else 0 + si.save() + si.submit() + + self.assertEqual(si.advances[0].allocated_amount, 200) + + # Check GL Entry against partial from advance + expected_gle = [ + [advance_account, 0.0, 1000.0, nowdate()], + [advance_account, 200.0, 0.0, nowdate()], + ["Cash - _TC", 1000.0, 0.0, nowdate()], + [debtors_acc, 0.0, 200.0, nowdate()], + ] + check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry") + si.reload() + self.assertEqual(si.outstanding_amount, 800.0) + + pr = frappe.get_doc("Payment Reconciliation") + pr.company = company + pr.party_type = "Customer" + pr.party = customer + pr.receivable_payable_account = debtors_acc + pr.default_advance_account = advance_account + pr.get_unreconciled_entries() + + # allocate some more of the same advance + # self.assertEqual(len(pr.invoices), 1) + # self.assertEqual(len(pr.payments), 1) + invoices = [x.as_dict() for x in pr.invoices if x.get("invoice_number") == si.name] + payments = [x.as_dict() for x in pr.payments if x.get("reference_name") == pe.name] + pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments})) + pr.allocation[0].allocated_amount = 300 + pr.reconcile() + + si.reload() + self.assertEqual(si.outstanding_amount, 500.0) + + # Check GL Entry against multi partial allocations from advance + expected_gle = [ + [advance_account, 0.0, 1000.0, nowdate()], + [advance_account, 200.0, 0.0, nowdate()], + [advance_account, 300.0, 0.0, nowdate()], + ["Cash - _TC", 1000.0, 0.0, nowdate()], + [debtors_acc, 0.0, 200.0, nowdate()], + [debtors_acc, 0.0, 300.0, nowdate()], + ] + check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry") + set_advance_flag(company="_Test Company", flag=0, default_account="") + def set_advance_flag(company, flag, default_account): frappe.db.set_value(