From ae6a81cd07e5f78a4b6107028a1322ec82978ae9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 30 Oct 2024 10:16:47 +0530 Subject: [PATCH] refactor: handle currency on advance payment ledger --- erpnext/controllers/accounts_controller.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 387fd8491f6..068075fea06 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1944,7 +1944,7 @@ class AccountsController(TransactionBase): adv = frappe.qb.DocType("Advance Payment Ledger Entry") advance = ( frappe.qb.from_(adv) - .select(adv.currency, Abs(Sum(adv.amount)).as_("amount")) + .select(adv.currency.as_("account_currency"), Abs(Sum(adv.amount)).as_("amount")) .where( (adv.against_voucher_type == self.doctype) & (adv.against_voucher_no == self.name) @@ -2618,6 +2618,11 @@ class AccountsController(TransactionBase): advance_doctype_references = [ x for x in self.references if x.reference_doctype in advance_payment_doctypes ] + currency = ( + self.paid_from_account_currency + if self.payment_type == "Receive" + else self.paid_to_account_currency + ) for x in advance_doctype_references: doc = frappe.new_doc("Advance Payment Ledger Entry") doc.company = self.company @@ -2626,6 +2631,7 @@ class AccountsController(TransactionBase): doc.against_voucher_type = x.reference_doctype doc.against_voucher_no = x.reference_name doc.amount = x.allocated_amount if self.docstatus == 1 else -1 * x.allocated_amount + doc.currency = currency doc.event = "Submit" if self.docstatus == 1 else "Cancel" doc.save()