From a4cff805f10ea20e9112cfa42e53c3389e7d71ce Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 10 Jun 2026 09:57:12 +0530 Subject: [PATCH] test(journal_entry): pin transaction-currency conversion in GL entries Mutation testing on gl_composer surfaced that the foreign-row debit/credit_in_transaction_currency conversion (amount / exchange_rate) was unverified -- a / vs * bug survived. Assert those fields in test_multi_currency and add a foreign-debit case so both conversion directions are now caught. --- .../journal_entry/test_journal_entry.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 19acb249fbb..a646ae64d61 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -169,8 +169,11 @@ class TestJournalEntry(ERPNextTestSuite): "debit_in_account_currency", "credit", "credit_in_account_currency", + "debit_in_transaction_currency", + "credit_in_transaction_currency", ] + # Transaction currency is USD (first foreign row); the INR row is converted at 1/50. self.expected_gle = [ { "account": "_Test Bank - _TC", @@ -179,6 +182,8 @@ class TestJournalEntry(ERPNextTestSuite): "debit_in_account_currency": 0, "credit": 5000, "credit_in_account_currency": 5000, + "debit_in_transaction_currency": 0, + "credit_in_transaction_currency": 100, }, { "account": "_Test Bank USD - _TC", @@ -187,6 +192,8 @@ class TestJournalEntry(ERPNextTestSuite): "debit_in_account_currency": 100, "credit": 0, "credit_in_account_currency": 0, + "debit_in_transaction_currency": 100, + "credit_in_transaction_currency": 0, }, ] @@ -203,6 +210,52 @@ class TestJournalEntry(ERPNextTestSuite): self.assertFalse(gle) + def test_multi_currency_transaction_currency_on_foreign_debit(self): + """Pin debit_in_transaction_currency for a foreign-currency debit row. + + Transaction currency is USD (the first foreign row); the INR debit row must be + converted at 1/exchange_rate, so 5000 INR -> 100 USD. Guards the / vs * direction. + """ + jv = frappe.new_doc("Journal Entry") + jv.company = "_Test Company" + jv.posting_date = nowdate() + jv.multi_currency = 1 + jv.append( + "accounts", + { + "account": "_Test Bank USD - _TC", + "cost_center": "_Test Cost Center - _TC", + "credit_in_account_currency": 100, + "exchange_rate": 50, + }, + ) + jv.append( + "accounts", + { + "account": "_Test Bank - _TC", + "cost_center": "_Test Cost Center - _TC", + "debit_in_account_currency": 5000, + "exchange_rate": 1, + }, + ) + jv.submit() + + self.voucher_no = jv.name + self.fields = ["account", "debit_in_transaction_currency", "credit_in_transaction_currency"] + self.expected_gle = [ + { + "account": "_Test Bank - _TC", + "debit_in_transaction_currency": 100, + "credit_in_transaction_currency": 0, + }, + { + "account": "_Test Bank USD - _TC", + "debit_in_transaction_currency": 0, + "credit_in_transaction_currency": 100, + }, + ] + self.check_gl_entries() + def test_reverse_journal_entry(self): from erpnext.accounts.doctype.journal_entry.mapper import make_reverse_journal_entry