From c0d3f8cbbe347f7326b4acead396e28daec01fc0 Mon Sep 17 00:00:00 2001 From: sudarsan2001 Date: Thu, 14 Nov 2024 01:11:12 +0530 Subject: [PATCH 1/5] fix: set debit in transaction currency in GL Entry (cherry picked from commit 29a6eb21a3cf33cd5d7a76e476646bf9c5e63c24) --- .../doctype/payment_entry/payment_entry.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 8832b87eec7..3efcb155781 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1248,13 +1248,22 @@ class PaymentEntry(AccountsController): base_unallocated_amount = self.unallocated_amount * exchange_rate gle = party_gl_dict.copy() - gle.update( - { - dr_or_cr + "_in_account_currency": self.unallocated_amount, - dr_or_cr: base_unallocated_amount, - } - ) + gle.update( + self.get_gl_dict( + { + "account": self.party_account, + "party_type": self.party_type, + "party": self.party, + "against": against_account, + "account_currency": self.party_account_currency, + "cost_center": self.cost_center, + dr_or_cr + "_in_account_currency": self.unallocated_amount, + dr_or_cr: base_unallocated_amount, + }, + item=self, + ) + ) if self.book_advance_payments_in_separate_party_account: gle.update( { From c30a17cd7a2fd009127d802596b66e81394c712d Mon Sep 17 00:00:00 2001 From: sudarsan2001 Date: Thu, 14 Nov 2024 01:28:16 +0530 Subject: [PATCH 2/5] test: add unit test to validate gl values (cherry picked from commit e8b8a589be75a840d75a2e46cf55364c040158a1) --- .../payment_entry/test_payment_entry.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index 771c91a462c..2dcd5d6076f 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -956,6 +956,51 @@ class TestPaymentEntry(FrappeTestCase): self.assertEqual(flt(expected_party_balance), party_balance) self.assertEqual(flt(expected_party_account_balance, 2), flt(party_account_balance, 2)) + def test_gl_of_multi_currency_payment_transaction(self): + from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records + + save_new_records(self.globalTestRecords["Currency Exchange"]) + paid_from = create_account( + parent_account="Current Liabilities - _TC", + account_name="Cash USD", + company="_Test Company", + account_type="Cash", + account_currency="USD", + ) + payment_entry = create_payment_entry( + party="_Test Supplier USD", + paid_from=paid_from, + paid_to="_Test Payable USD - _TC", + paid_amount=100, + save=True, + ) + payment_entry.source_exchange_rate = 84.4 + payment_entry.target_exchange_rate = 84.4 + payment_entry.save() + payment_entry = payment_entry.submit() + gle = qb.DocType("GL Entry") + gl_entries = ( + qb.from_(gle) + .select( + gle.account, + gle.debit, + gle.credit, + gle.debit_in_account_currency, + gle.credit_in_account_currency, + gle.debit_in_transaction_currency, + gle.credit_in_transaction_currency, + ) + .orderby(gle.account) + .where(gle.voucher_no == payment_entry.name) + .run() + ) + expected_gl_entries = ( + ("_Test Payable USD - _TC", 8440.0, 0, 100.0, 0.0, 8440.0, 0.0), + (paid_from, 0, 8440.0, 0, 100.0, 0, 8440.0), + ) + + self.assertEqual(gl_entries, expected_gl_entries) + def test_multi_currency_payment_entry_with_taxes(self): payment_entry = create_payment_entry( party="_Test Supplier USD", paid_to="_Test Payable USD - _TC", save=True From 7cc31df58774d77ef185c0f327ae0623a156b675 Mon Sep 17 00:00:00 2001 From: sudarsan2001 Date: Thu, 14 Nov 2024 10:59:51 +0530 Subject: [PATCH 3/5] chore: change account name (cherry picked from commit 4a1cd5a8d6bf920b682fa731f1fc087e09ea94e5) --- .../accounts/doctype/payment_entry/test_payment_entry.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index 2dcd5d6076f..c61598b54a5 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -962,7 +962,7 @@ class TestPaymentEntry(FrappeTestCase): save_new_records(self.globalTestRecords["Currency Exchange"]) paid_from = create_account( parent_account="Current Liabilities - _TC", - account_name="Cash USD", + account_name="_Test Cash USD", company="_Test Company", account_type="Cash", account_currency="USD", @@ -995,10 +995,9 @@ class TestPaymentEntry(FrappeTestCase): .run() ) expected_gl_entries = ( - ("_Test Payable USD - _TC", 8440.0, 0, 100.0, 0.0, 8440.0, 0.0), - (paid_from, 0, 8440.0, 0, 100.0, 0, 8440.0), + (paid_from, 0.0, 8440.0, 0.0, 100.0, 0.0, 8440.0), + ("_Test Payable USD - _TC", 8440.0, 0.0, 100.0, 0.0, 8440.0, 0.0), ) - self.assertEqual(gl_entries, expected_gl_entries) def test_multi_currency_payment_entry_with_taxes(self): From d7deed6c450708e74a58469d852f909d9893a16a Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 18 Nov 2024 16:25:44 +0530 Subject: [PATCH 4/5] refactor: assume any of the foreign currency as transaction currency On a foreign currency payment entry, assume any one of the foreign currency as the transaction currency (cherry picked from commit 6681882bd8003cac1d8d4eda76141ec5a6b6b246) --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 3efcb155781..b9fad5c9010 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1146,6 +1146,12 @@ class PaymentEntry(AccountsController): if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"): self.setup_party_account_field() + company_currency = erpnext.get_company_currency(self.company) + if self.paid_from_account_currency != company_currency: + self.currency = self.paid_from_account_currency + elif self.paid_to_account_currency != company_currency: + self.currency = self.paid_to_account_currency + gl_entries = [] self.add_party_gl_entries(gl_entries) self.add_bank_gl_entries(gl_entries) From 8cc59e3be71f005e2c970eba8a654bbd11eb95d3 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 18 Nov 2024 16:39:06 +0530 Subject: [PATCH 5/5] refactor: update test case (cherry picked from commit 4aab6f55f5bb47719fad95e366516a42b7f859e3) --- .../doctype/payment_entry/test_payment_entry.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index c61598b54a5..8758110534f 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -957,9 +957,12 @@ class TestPaymentEntry(FrappeTestCase): self.assertEqual(flt(expected_party_account_balance, 2), flt(party_account_balance, 2)) def test_gl_of_multi_currency_payment_transaction(self): - from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records + from erpnext.setup.doctype.currency_exchange.test_currency_exchange import ( + save_new_records, + test_records, + ) - save_new_records(self.globalTestRecords["Currency Exchange"]) + save_new_records(test_records) paid_from = create_account( parent_account="Current Liabilities - _TC", account_name="_Test Cash USD", @@ -995,8 +998,8 @@ class TestPaymentEntry(FrappeTestCase): .run() ) expected_gl_entries = ( - (paid_from, 0.0, 8440.0, 0.0, 100.0, 0.0, 8440.0), - ("_Test Payable USD - _TC", 8440.0, 0.0, 100.0, 0.0, 8440.0, 0.0), + (paid_from, 0.0, 8440.0, 0.0, 100.0, 0.0, 100.0), + ("_Test Payable USD - _TC", 8440.0, 0.0, 100.0, 0.0, 100.0, 0.0), ) self.assertEqual(gl_entries, expected_gl_entries)