From 46bea0e56f45d81a1f06d78fd77e648888d9a179 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 31 Aug 2023 16:55:23 +0530 Subject: [PATCH] fix: calcuate received/paid amount on rate change in PE (cherry picked from commit 64d835374b281fc7406e574b0306ed48656010ca) --- erpnext/accounts/doctype/payment_entry/payment_entry.js | 8 ++++++++ erpnext/accounts/doctype/payment_entry/payment_entry.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index cd788a896a83..4e3cf35b6186 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -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); @@ -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", @@ -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); diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 765e69b75bd0..1c6c99ed3e50 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -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) @@ -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