Fixed curency exchange bug in payment entry
This commit is contained in:
parent
55b3b4e27b
commit
5d5484805a
|
|
@ -47,5 +47,59 @@ frappe.ui.form.on('Payment Entry', {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Переопределение received_amount
|
||||||
|
received_amount: function (frm) {
|
||||||
|
if (frm.set_paid_amount_based_on_received_amount) return;
|
||||||
|
|
||||||
|
const company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
|
||||||
|
const from_currency = frm.doc.paid_from_account_currency;
|
||||||
|
const to_currency = frm.doc.paid_to_account_currency;
|
||||||
|
|
||||||
|
const from_rate = frm.doc.source_exchange_rate || 1;
|
||||||
|
const to_rate = frm.doc.target_exchange_rate || 1;
|
||||||
|
|
||||||
|
const cross_rate = from_currency === to_currency ? 1 : from_rate / to_rate;
|
||||||
|
|
||||||
|
frm.set_paid_amount_based_on_received_amount = true;
|
||||||
|
frm.set_value(
|
||||||
|
"paid_amount",
|
||||||
|
flt(frm.doc.received_amount / cross_rate, precision("paid_amount"))
|
||||||
|
);
|
||||||
|
frm.set_paid_amount_based_on_received_amount = false;
|
||||||
|
|
||||||
|
frm.set_value("base_received_amount", flt(frm.doc.received_amount * to_rate));
|
||||||
|
frm.events.hide_unhide_fields(frm);
|
||||||
|
frm.trigger("set_difference_amount");
|
||||||
|
},
|
||||||
|
|
||||||
|
// Переопределение paid_amount
|
||||||
|
paid_amount: function (frm) {
|
||||||
|
if (frm.set_paid_amount_based_on_received_amount) return;
|
||||||
|
|
||||||
|
const company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
|
||||||
|
const from_currency = frm.doc.paid_from_account_currency;
|
||||||
|
const to_currency = frm.doc.paid_to_account_currency;
|
||||||
|
|
||||||
|
// Получаем курсы валют относительно базовой валюты компании
|
||||||
|
const from_rate = frm.doc.source_exchange_rate || 1;
|
||||||
|
const to_rate = frm.doc.target_exchange_rate || 1;
|
||||||
|
|
||||||
|
// Рассчитываем кросс-курс между валютами списания и зачисления
|
||||||
|
const cross_rate = from_currency === to_currency ? 1 : from_rate / to_rate;
|
||||||
|
|
||||||
|
// Обновляем Received Amount
|
||||||
|
frm.set_paid_amount_based_on_received_amount = true;
|
||||||
|
frm.set_value(
|
||||||
|
"received_amount",
|
||||||
|
flt(frm.doc.paid_amount * cross_rate, precision("received_amount"))
|
||||||
|
);
|
||||||
|
frm.set_paid_amount_based_on_received_amount = false;
|
||||||
|
|
||||||
|
// Обновляем base_paid_amount (в базовой валюте компании)
|
||||||
|
frm.set_value("base_paid_amount", flt(frm.doc.paid_amount * from_rate));
|
||||||
|
frm.events.hide_unhide_fields(frm);
|
||||||
|
frm.trigger("set_difference_amount");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue