diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 1f23fe1d5425..712023fdf962 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1735,7 +1735,7 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre if not total_amount: if party_account_currency == company_currency: # for handling cases that don't have multi-currency (base field) - total_amount = ref_doc.get("grand_total") or ref_doc.get("base_grand_total") + total_amount = ref_doc.get("base_grand_total") or ref_doc.get("grand_total") exchange_rate = 1 else: total_amount = ref_doc.get("grand_total") diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index 278b12f6595f..ae2625b65390 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -11,6 +11,7 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import ( InvalidPaymentEntry, get_payment_entry, + get_reference_details, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( make_purchase_invoice, @@ -1037,6 +1038,29 @@ def test_duplicate_payment_entry_partial_allocate_amount(self): self.assertRaises(frappe.ValidationError, pe_draft.submit) + def test_details_update_on_reference_table(self): + so = make_sales_order( + customer="_Test Customer USD", currency="USD", qty=1, rate=100, do_not_submit=True + ) + so.conversion_rate = 50 + so.submit() + pe = get_payment_entry("Sales Order", so.name) + pe.references.clear() + pe.paid_from = "Debtors - _TC" + pe.paid_from_account_currency = "INR" + pe.source_exchange_rate = 50 + pe.save() + + ref_details = get_reference_details(so.doctype, so.name, pe.paid_from_account_currency) + expected_response = { + "total_amount": 5000.0, + "outstanding_amount": 5000.0, + "exchange_rate": 1.0, + "due_date": None, + "bill_no": None, + } + self.assertDictEqual(ref_details, expected_response) + def create_payment_entry(**args): payment_entry = frappe.new_doc("Payment Entry")