fix(payment_entry): fix paid/received amount calculation for multi-currency accounts (backport #54963) (#54969)

* fix(payment_entry): `paid_amount` and `received_amount` calculation depending upon `account_currency`

(cherry picked from commit 69642860ee)

# Conflicts:
#	erpnext/accounts/doctype/payment_entry/payment_entry.json

* chore: resolve conflicts

---------

Co-authored-by: diptanilsaha <diptanil@frappe.io>
This commit is contained in:
mergify[bot]
2026-05-15 10:33:07 +00:00
committed by GitHub
parent 2b2eb2fa27
commit 651af67b26
2 changed files with 45 additions and 63 deletions

View File

@@ -725,31 +725,12 @@ frappe.ui.form.on("Payment Entry", {
if (!frm.doc.paid_from_account_currency || !frm.doc.company) return; if (!frm.doc.paid_from_account_currency || !frm.doc.company) return;
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
if (frm.doc.paid_from_account_currency == company_currency) { frm.events.set_current_exchange_rate(
frm.set_value("source_exchange_rate", 1); frm,
} else if (frm.doc.paid_from) { "source_exchange_rate",
if (["Internal Transfer", "Pay"].includes(frm.doc.payment_type)) { frm.doc.paid_from_account_currency,
let company_currency = frappe.get_doc(":Company", frm.doc.company)?.default_currency; company_currency
frappe.call({ );
method: "erpnext.setup.utils.get_exchange_rate",
args: {
from_currency: frm.doc.paid_from_account_currency,
to_currency: company_currency,
transaction_date: frm.doc.posting_date,
},
callback: function (r, rt) {
frm.set_value("source_exchange_rate", r.message);
},
});
} else {
frm.events.set_current_exchange_rate(
frm,
"source_exchange_rate",
frm.doc.paid_from_account_currency,
company_currency
);
}
}
}, },
paid_to_account_currency: function (frm) { paid_to_account_currency: function (frm) {
@@ -781,49 +762,24 @@ frappe.ui.form.on("Payment Entry", {
posting_date: function (frm) { posting_date: function (frm) {
frm.events.paid_from_account_currency(frm); frm.events.paid_from_account_currency(frm);
frm.events.paid_to_account_currency(frm);
}, },
source_exchange_rate: function (frm) { source_exchange_rate: function (frm) {
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
if (frm.doc.paid_amount) {
frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
// target exchange rate should always be same as source if both account currencies is same
if (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) {
frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
} else if (company_currency == frm.doc.paid_to_account_currency) {
frm.set_value("received_amount", frm.doc.base_paid_amount);
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
}
// set_unallocated_amount is called by below method,
// no need trigger separately
frm.events.set_total_allocated_amount(frm);
}
// Make read only if Accounts Settings doesn't allow stale rates
frm.set_df_property("source_exchange_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1);
},
target_exchange_rate: function (frm) {
frm.set_paid_amount_based_on_received_amount = true; frm.set_paid_amount_based_on_received_amount = true;
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
if (frm.doc.received_amount) { if (frm.doc.base_received_amount && frm.doc.source_exchange_rate) {
frm.set_value( frm.set_value("base_paid_amount", frm.doc.base_received_amount);
"base_received_amount",
flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate)
);
if ( // target exchange rate should always be same as source if both account currencies is same
!frm.doc.source_exchange_rate && if (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) {
frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
) { } else {
frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate); frm.set_value(
frm.set_value("base_paid_amount", frm.doc.base_received_amount); "paid_amount",
} else if (company_currency == frm.doc.paid_from_account_currency) { flt(frm.doc.base_paid_amount) / flt(frm.doc.source_exchange_rate)
frm.set_value("paid_amount", frm.doc.base_received_amount); );
frm.set_value("base_paid_amount", frm.doc.base_received_amount);
} }
// set_unallocated_amount is called by below method, // set_unallocated_amount is called by below method,
@@ -832,6 +788,32 @@ frappe.ui.form.on("Payment Entry", {
} }
frm.set_paid_amount_based_on_received_amount = false; frm.set_paid_amount_based_on_received_amount = false;
// Make read only if Accounts Settings doesn't allow stale rates
frm.set_df_property("source_exchange_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1);
},
target_exchange_rate: function (frm) {
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
if (frm.doc.base_paid_amount && frm.doc.target_exchange_rate) {
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
if (
!frm.doc.source_exchange_rate &&
frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency
) {
frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate);
} else {
frm.set_value(
"received_amount",
flt(frm.doc.base_received_amount) / flt(frm.doc.target_exchange_rate)
);
}
// set_unallocated_amount is called by below method,
// no need trigger separately
frm.events.set_total_allocated_amount(frm);
}
// Make read only if Accounts Settings doesn't allow stale rates // Make read only if Accounts Settings doesn't allow stale rates
frm.set_df_property("target_exchange_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1); frm.set_df_property("target_exchange_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1);
}, },

View File

@@ -350,7 +350,7 @@
"reqd": 1 "reqd": 1
}, },
{ {
"depends_on": "doc.received_amount", "depends_on": "eval:doc.received_amount;",
"fieldname": "base_received_amount", "fieldname": "base_received_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Received Amount (Company Currency)", "label": "Received Amount (Company Currency)",
@@ -800,7 +800,7 @@
"table_fieldname": "payment_entries" "table_fieldname": "payment_entries"
} }
], ],
"modified": "2025-05-15 18:01:04.013025", "modified": "2026-05-15 13:31:01.166010",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Payment Entry", "name": "Payment Entry",