fix: use reference type name to update exc rate
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 90ff5b1..a2a5bbc 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -484,7 +484,7 @@
self,
force: bool = False,
update_ref_details_only_for: list | None = None,
- ref_exchange_rate: float | None = None,
+ reference_exchange_details: dict | None = None,
) -> None:
for d in self.get("references"):
if d.allocated_amount:
@@ -499,8 +499,12 @@
)
# Only update exchange rate when the reference is Journal Entry
- if ref_exchange_rate and d.reference_doctype == "Journal Entry":
- ref_details.update({"exchange_rate": ref_exchange_rate})
+ if (
+ reference_exchange_details
+ and d.reference_doctype == reference_exchange_details.reference_doctype
+ and d.reference_name == reference_exchange_details.reference_name
+ ):
+ ref_details.update({"exchange_rate": reference_exchange_details.exchange_rate})
for field, value in ref_details.items():
if d.exchange_gain_loss:
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index b61f195..869fd42 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -720,7 +720,19 @@
payment_entry.setup_party_account_field()
payment_entry.set_missing_values()
if not skip_ref_details_update_for_pe:
- payment_entry.set_missing_ref_details(ref_exchange_rate=d.exchange_rate or None)
+ reference_exchange_details = frappe._dict()
+ if d.against_voucher_type == "Journal Entry" and d.exchange_rate:
+ reference_exchange_details.update(
+ {
+ "reference_doctype": d.against_voucher_type,
+ "reference_name": d.against_voucher,
+ "exchange_rate": d.exchange_rate,
+ }
+ )
+ payment_entry.set_missing_ref_details(
+ update_ref_details_only_for=[(d.against_voucher_type, d.against_voucher)],
+ reference_exchange_details=reference_exchange_details,
+ )
payment_entry.set_amounts()
payment_entry.make_exchange_gain_loss_journal(