mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
Merge pull request #30512 from frappe/mergify/bp/version-13-hotfix/pr-30486
fix: Account currency validation (backport #30486)
This commit is contained in:
@@ -204,7 +204,9 @@ class Account(NestedSet):
|
|||||||
if not self.account_currency:
|
if not self.account_currency:
|
||||||
self.account_currency = frappe.get_cached_value("Company", self.company, "default_currency")
|
self.account_currency = frappe.get_cached_value("Company", self.company, "default_currency")
|
||||||
|
|
||||||
elif self.account_currency != frappe.db.get_value("Account", self.name, "account_currency"):
|
gl_currency = frappe.db.get_value("GL Entry", {"account": self.name}, "account_currency")
|
||||||
|
|
||||||
|
if gl_currency and self.account_currency != gl_currency:
|
||||||
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
||||||
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
||||||
|
|
||||||
|
|||||||
@@ -241,6 +241,28 @@ class TestAccount(unittest.TestCase):
|
|||||||
for doc in to_delete:
|
for doc in to_delete:
|
||||||
frappe.delete_doc("Account", doc)
|
frappe.delete_doc("Account", doc)
|
||||||
|
|
||||||
|
def test_validate_account_currency(self):
|
||||||
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||||
|
|
||||||
|
if not frappe.db.get_value("Account", "Test Currency Account - _TC"):
|
||||||
|
acc = frappe.new_doc("Account")
|
||||||
|
acc.account_name = "Test Currency Account"
|
||||||
|
acc.parent_account = "Tax Assets - _TC"
|
||||||
|
acc.company = "_Test Company"
|
||||||
|
acc.insert()
|
||||||
|
else:
|
||||||
|
acc = frappe.get_doc("Account", "Test Currency Account - _TC")
|
||||||
|
|
||||||
|
self.assertEqual(acc.account_currency, "INR")
|
||||||
|
|
||||||
|
# Make a JV against this account
|
||||||
|
make_journal_entry(
|
||||||
|
"Test Currency Account - _TC", "Miscellaneous Expenses - _TC", 100, submit=True
|
||||||
|
)
|
||||||
|
|
||||||
|
acc.account_currency = "USD"
|
||||||
|
self.assertRaises(frappe.ValidationError, acc.save)
|
||||||
|
|
||||||
|
|
||||||
def _make_test_records(verbose=None):
|
def _make_test_records(verbose=None):
|
||||||
from frappe.test_runner import make_test_objects
|
from frappe.test_runner import make_test_objects
|
||||||
|
|||||||
Reference in New Issue
Block a user