Merge pull request #39336 from ruthra-kumar/better_validation_on_bank_transaction
refactor: disallow bank transactions on different currencies
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 5a6bb69..adf5925 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 @@
"deposit": 100,
"bank_account": self.bank_account,
"reference_number": "123",
+ "currency": "INR",
}
)
.save()
diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py
index c38d273..fef3b56 100644
--- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py
+++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py
@@ -49,6 +49,24 @@
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(
+ _(
+ "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)
+ )
+ )
def set_status(self):
if self.docstatus == 2: