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