From cdd0acc672e471d94693c04079ab78ba48b82a30 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 12 Jan 2024 16:33:41 +0530 Subject: [PATCH] refactor: disallow bank transactions on different currencies --- .../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 1d6cb8e2c0..a049d4084a 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -48,6 +48,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: