Skip to content

Commit

Permalink
Merge pull request #36890 from frappe/mergify/bp/version-14/pr-36888
Browse files Browse the repository at this point in the history
fix: calcuate received/paid amount on exchange rate change in Payment Entry (backport #36888)
  • Loading branch information
ruthra-kumar authored Aug 31, 2023
2 parents b95ab34 + 46bea0e commit 38d27a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,16 @@ frappe.ui.form.on('Payment Entry', {
},

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);
}

frm.events.set_unallocated_amount(frm);
Expand All @@ -543,6 +547,7 @@ frappe.ui.form.on('Payment Entry', {

target_exchange_rate: function(frm) {
frm.set_paid_amount_based_on_received_amount = true;
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;

if (frm.doc.received_amount) {
frm.set_value("base_received_amount",
Expand All @@ -552,6 +557,9 @@ frappe.ui.form.on('Payment Entry', {
(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("base_paid_amount", frm.doc.base_received_amount);
} else if (company_currency == frm.doc.paid_from_account_currency) {
frm.set_value("paid_amount", frm.doc.base_received_amount);
frm.set_value("base_paid_amount", frm.doc.base_received_amount);
}

frm.events.set_unallocated_amount(frm);
Expand Down
4 changes: 2 additions & 2 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,7 @@ def set_paid_amount_and_received_amount(
if bank_amount:
received_amount = bank_amount
else:
if company_currency != bank.account_currency:
if bank and company_currency != bank.account_currency:
received_amount = paid_amount / doc.get("conversion_rate", 1)
else:
received_amount = paid_amount * doc.get("conversion_rate", 1)
Expand All @@ -2176,7 +2176,7 @@ def set_paid_amount_and_received_amount(
if bank_amount:
paid_amount = bank_amount
else:
if company_currency != bank.account_currency:
if bank and company_currency != bank.account_currency:
paid_amount = received_amount / doc.get("conversion_rate", 1)
else:
# if party account currency and bank currency is different then populate paid amount as well
Expand Down

0 comments on commit 38d27a1

Please sign in to comment.