From dbbba046ab0be6dee68b869174653278fdd5e60d Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 12 Jan 2024 16:33:41 +0530 Subject: [PATCH 1/3] refactor: disallow bank transactions on different currencies (cherry picked from commit cdd0acc672e471d94693c04079ab78ba48b82a30) --- .../doctype/bank_transaction/bank_transaction.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index c38d27355f..15d7786de7 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -49,6 +49,22 @@ class BankTransaction(Document): def validate(self): self.validate_duplicate_references() + self.validate_currency() + + def validate_currency(self): + """ + Bank Transaction should be on the same currency as the Bank Account. + """ + if self.currency and self.bank_account: + account = frappe.get_cached_value("Bank Account", self.bank_account, "account") + account_currency = frappe.get_cached_value("Account", account, "account_currency") + + if self.currency != account_currency: + frappe.throw( + _("Currency {0} cannot be different from Bank Account({1}) Currency: {2}").format( + frappe.bold(self.currency), frappe.bold(self.bank_account), frappe.bold(account_currency) + ) + ) def set_status(self): if self.docstatus == 2: From f609b8ae5d7f09bbb4daee59488ac4cbc7073276 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sun, 14 Jan 2024 18:04:15 +0530 Subject: [PATCH 2/3] refactor: better error message (cherry picked from commit b4354cbc8dfb22fafaed2cd39b92c438e5f199db) --- erpnext/accounts/doctype/bank_transaction/bank_transaction.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index 15d7786de7..fef3b569ed 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -61,7 +61,9 @@ class BankTransaction(Document): if self.currency != account_currency: frappe.throw( - _("Currency {0} cannot be different from Bank Account({1}) Currency: {2}").format( + _( + "Transaction currency: {0} cannot be different from Bank Account({1}) currency: {2}" + ).format( frappe.bold(self.currency), frappe.bold(self.bank_account), frappe.bold(account_currency) ) ) From 32c61117285fb7c58cb68d2d3120579382587836 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sun, 14 Jan 2024 18:09:19 +0530 Subject: [PATCH 3/3] refactor(test): supply default currency to Bank Transaction (cherry picked from commit a27a4db3de6d6df7dd340d4212c114b7f4c0762c) --- .../bank_reconciliation_tool/test_bank_reconciliation_tool.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py index 5a6bb6976f..adf5925443 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py @@ -76,6 +76,7 @@ class TestBankReconciliationTool(AccountsTestMixin, FrappeTestCase): "deposit": 100, "bank_account": self.bank_account, "reference_number": "123", + "currency": "INR", } ) .save()