mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-14 15:11:52 +00:00
Co-authored-by: Ravibharathi <131471282+ravibharathi656@users.noreply.github.com> Co-authored-by: ervishnucs <ervishnucs369@gmail.com> fix(payment_entry): recompute base amount when exchange rate changes (#56136)
This commit is contained in:
@@ -769,17 +769,21 @@ frappe.ui.form.on("Payment Entry", {
|
|||||||
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.base_received_amount && frm.doc.source_exchange_rate) {
|
if (frm.doc.paid_amount && frm.doc.source_exchange_rate) {
|
||||||
frm.set_value("base_paid_amount", frm.doc.base_received_amount);
|
frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
|
||||||
|
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
|
||||||
|
|
||||||
// target exchange rate should always be same as source if both account currencies is same
|
// 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) {
|
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("target_exchange_rate", frm.doc.source_exchange_rate);
|
||||||
|
frm.set_value("received_amount", frm.doc.paid_amount);
|
||||||
} else {
|
} else {
|
||||||
frm.set_value(
|
const target_rate =
|
||||||
"paid_amount",
|
flt(frm.doc.target_exchange_rate) ||
|
||||||
flt(frm.doc.base_paid_amount) / flt(frm.doc.source_exchange_rate)
|
(company_currency == frm.doc.paid_to_account_currency ? 1 : 0);
|
||||||
);
|
if (target_rate) {
|
||||||
|
frm.set_value("received_amount", flt(frm.doc.base_received_amount) / target_rate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_unallocated_amount is called by below method,
|
// set_unallocated_amount is called by below method,
|
||||||
@@ -795,18 +799,23 @@ frappe.ui.form.on("Payment Entry", {
|
|||||||
target_exchange_rate: function (frm) {
|
target_exchange_rate: function (frm) {
|
||||||
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.base_paid_amount && frm.doc.target_exchange_rate) {
|
if (frm.doc.received_amount && frm.doc.target_exchange_rate) {
|
||||||
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
|
frm.set_value(
|
||||||
if (
|
"base_received_amount",
|
||||||
!frm.doc.source_exchange_rate &&
|
flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate)
|
||||||
frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency
|
);
|
||||||
) {
|
frm.set_value("base_paid_amount", frm.doc.base_received_amount);
|
||||||
|
|
||||||
|
if (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) {
|
||||||
frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate);
|
frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate);
|
||||||
|
frm.set_value("paid_amount", frm.doc.received_amount);
|
||||||
} else {
|
} else {
|
||||||
frm.set_value(
|
const source_rate =
|
||||||
"received_amount",
|
flt(frm.doc.source_exchange_rate) ||
|
||||||
flt(frm.doc.base_received_amount) / flt(frm.doc.target_exchange_rate)
|
(company_currency == frm.doc.paid_from_account_currency ? 1 : 0);
|
||||||
);
|
if (source_rate) {
|
||||||
|
frm.set_value("paid_amount", flt(frm.doc.base_paid_amount) / source_rate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_unallocated_amount is called by below method,
|
// set_unallocated_amount is called by below method,
|
||||||
|
|||||||
Reference in New Issue
Block a user