From dbe153a15ed708c74d4adcc1cb5555211ee7fe99 Mon Sep 17 00:00:00 2001 From: Vishnu Priya Baskaran <145791817+ervishnucs@users.noreply.github.com> Date: Wed, 2 Sep 2026 12:30:08 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20include=20payment=20deductions=20in=20sa?= =?UTF-8?q?les/purchase=20register=20ledger=20bal=E2=80=A6=20(#58437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erpnext/accounts/report/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/erpnext/accounts/report/utils.py b/erpnext/accounts/report/utils.py index ad315e031b0..6179cf6ca86 100644 --- a/erpnext/accounts/report/utils.py +++ b/erpnext/accounts/report/utils.py @@ -309,6 +309,9 @@ def get_payment_entries(filters, args): pe.mode_of_payment, pe.project, pe.cost_center, + pe.payment_type, + pe.source_exchange_rate, + pe.target_exchange_rate, ) .where( (pe.docstatus == 1) @@ -319,6 +322,22 @@ def get_payment_entries(filters, args): ) query = apply_common_conditions(filters, query, doctype="Payment Entry", payments=True) payment_entries = query.run(as_dict=True) + + if payment_entries: + ded = frappe.qb.DocType("Payment Entry Deduction") + deduction_totals = frappe._dict( + frappe.qb.from_(ded) + .select(ded.parent, Sum(ded.amount)) + .where(ded.parent.isin([d.name for d in payment_entries]) & (ded.is_exchange_gain_loss == 0)) + .groupby(ded.parent) + .run() + ) + for d in payment_entries: + exchange_rate = ( + d.source_exchange_rate if d.payment_type == "Receive" else d.target_exchange_rate + ) or 1 + d.base_grand_total = flt(d.base_grand_total) + flt(deduction_totals.get(d.name)) / exchange_rate + return payment_entries