From 3327599c9d5f27b10668b9e6fbef72acdcb6d5f0 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 29 Feb 2024 17:18:42 +0530 Subject: [PATCH 1/2] fix: include Debit To/Credit To account while fetching advance --- erpnext/controllers/accounts_controller.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 063c1e353f..fbc3a8986d 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1128,21 +1128,24 @@ class AccountsController(TransactionBase): self.append("advances", advance_row) def get_advance_entries(self, include_unallocated=True): + party_account = [] if self.doctype == "Sales Invoice": party_type = "Customer" party = self.customer amount_field = "credit_in_account_currency" order_field = "sales_order" order_doctype = "Sales Order" + party_account.append(self.debit_to) else: party_type = "Supplier" party = self.supplier amount_field = "debit_in_account_currency" order_field = "purchase_order" order_doctype = "Purchase Order" + party_account.append(self.credit_to) - party_account = get_party_account( - party_type, party=party, company=self.company, include_advance=True + party_account.extend( + get_party_account(party_type, party=party, company=self.company, include_advance=True) ) order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field))) From 646e9ca0dd484b65d4f3bbe674b63760f8e3d5ce Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 29 Feb 2024 17:31:08 +0530 Subject: [PATCH 2/2] test: advance pulling logic on Sales/Purchase Invoice --- .../sales_invoice/test_sales_invoice.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 8c3aedebcd..6da9244301 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3577,6 +3577,33 @@ class TestSalesInvoice(FrappeTestCase): check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry") set_advance_flag(company="_Test Company", flag=0, default_account="") + def test_pulling_advance_based_on_debit_to(self): + from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry + + debtors2 = create_account( + parent_account="Accounts Receivable - _TC", + account_name="Debtors 2", + company="_Test Company", + account_type="Receivable", + ) + si = create_sales_invoice(do_not_submit=True) + si.debit_to = debtors2 + si.save() + + pe = create_payment_entry( + company=si.company, + payment_type="Receive", + party_type="Customer", + party=si.customer, + paid_from=debtors2, + paid_to="Cash - _TC", + paid_amount=1000, + ) + pe.submit() + advances = si.get_advance_entries() + self.assertEqual(1, len(advances)) + self.assertEqual(advances[0].reference_name, pe.name) + def set_advance_flag(company, flag, default_account): frappe.db.set_value(