Skip to content

Commit e09406d

Browse files
ravibharathi656mergify[bot]
authored andcommitted
fix: correct exchange gain loss in ppr
(cherry picked from commit 02e9603)
1 parent 3bc348d commit e09406d

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,9 @@ def reconcile(doc: None | str = None) -> None:
415415
for x in allocations:
416416
pr.append("allocation", x)
417417

418+
skip_ref_details_update_for_pe = check_multi_currency(pr)
418419
# reconcile
419-
pr.reconcile_allocations(skip_ref_details_update_for_pe=True)
420+
pr.reconcile_allocations(skip_ref_details_update_for_pe=skip_ref_details_update_for_pe)
420421

421422
# If Payment Entry, update details only for newly linked references
422423
# This is for performance
@@ -504,6 +505,37 @@ def reconcile(doc: None | str = None) -> None:
504505
frappe.db.set_value("Process Payment Reconciliation", doc, "status", "Completed")
505506

506507

508+
def check_multi_currency(pr_doc):
509+
GL = frappe.qb.DocType("GL Entry")
510+
Account = frappe.qb.DocType("Account")
511+
512+
def get_account_currency(voucher_type, voucher_no):
513+
currency = (
514+
frappe.qb.from_(GL)
515+
.join(Account)
516+
.on(GL.account == Account.name)
517+
.select(Account.account_currency)
518+
.where(
519+
(GL.voucher_type == voucher_type)
520+
& (GL.voucher_no == voucher_no)
521+
& (Account.account_type.isin(["Payable", "Receivable"]))
522+
)
523+
.limit(1)
524+
).run(as_dict=True)
525+
526+
return currency[0].account_currency if currency else None
527+
528+
for allocation in pr_doc.allocation:
529+
reference_currency = get_account_currency(allocation.reference_type, allocation.reference_name)
530+
531+
invoice_currency = get_account_currency(allocation.invoice_type, allocation.invoice_number)
532+
533+
if reference_currency != invoice_currency:
534+
return True
535+
536+
return False
537+
538+
507539
@frappe.whitelist()
508540
def is_any_doc_running(for_filter: str | dict | None = None) -> str | None:
509541
running_doc = None

0 commit comments

Comments
 (0)