mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 21:49:18 +00:00
refactor: use common functionality to validate account number (#42842)
feat: Allow unique Account number by root type (not unique for accros all Accounts)
This commit is contained in:
@@ -102,14 +102,12 @@ class Account(NestedSet):
|
|||||||
self.name = get_autoname_with_number(self.account_number, self.account_name, self.company)
|
self.name = get_autoname_with_number(self.account_number, self.account_name, self.company)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
from erpnext.accounts.utils import validate_field_number
|
|
||||||
|
|
||||||
if frappe.local.flags.allow_unverified_charts:
|
if frappe.local.flags.allow_unverified_charts:
|
||||||
return
|
return
|
||||||
self.validate_parent()
|
self.validate_parent()
|
||||||
self.validate_parent_child_account_type()
|
self.validate_parent_child_account_type()
|
||||||
self.validate_root_details()
|
self.validate_root_details()
|
||||||
validate_field_number("Account", self.name, self.account_number, self.company, "account_number")
|
self.validate_account_number()
|
||||||
self.validate_group_or_ledger()
|
self.validate_group_or_ledger()
|
||||||
self.set_root_and_report_type()
|
self.set_root_and_report_type()
|
||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
@@ -310,6 +308,22 @@ class Account(NestedSet):
|
|||||||
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"))
|
||||||
|
|
||||||
|
def validate_account_number(self, account_number=None):
|
||||||
|
if not account_number:
|
||||||
|
account_number = self.account_number
|
||||||
|
|
||||||
|
if account_number:
|
||||||
|
account_with_same_number = frappe.db.get_value(
|
||||||
|
"Account",
|
||||||
|
{"account_number": account_number, "company": self.company, "name": ["!=", self.name]},
|
||||||
|
)
|
||||||
|
if account_with_same_number:
|
||||||
|
frappe.throw(
|
||||||
|
_("Account Number {0} already used in account {1}").format(
|
||||||
|
account_number, account_with_same_number
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def create_account_for_child_company(self, parent_acc_name_map, descendants, parent_acc_name):
|
def create_account_for_child_company(self, parent_acc_name_map, descendants, parent_acc_name):
|
||||||
for company in descendants:
|
for company in descendants:
|
||||||
company_bold = frappe.bold(company)
|
company_bold = frappe.bold(company)
|
||||||
@@ -463,19 +477,6 @@ def get_account_autoname(account_number, account_name, company):
|
|||||||
return " - ".join(parts)
|
return " - ".join(parts)
|
||||||
|
|
||||||
|
|
||||||
def validate_account_number(name, account_number, company):
|
|
||||||
if account_number:
|
|
||||||
account_with_same_number = frappe.db.get_value(
|
|
||||||
"Account", {"account_number": account_number, "company": company, "name": ["!=", name]}
|
|
||||||
)
|
|
||||||
if account_with_same_number:
|
|
||||||
frappe.throw(
|
|
||||||
_("Account Number {0} already used in account {1}").format(
|
|
||||||
account_number, account_with_same_number
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def update_account_number(name, account_name, account_number=None, from_descendant=False):
|
def update_account_number(name, account_name, account_number=None, from_descendant=False):
|
||||||
account = frappe.get_cached_doc("Account", name)
|
account = frappe.get_cached_doc("Account", name)
|
||||||
@@ -516,7 +517,7 @@ def update_account_number(name, account_name, account_number=None, from_descenda
|
|||||||
|
|
||||||
frappe.throw(message, title=_("Rename Not Allowed"))
|
frappe.throw(message, title=_("Rename Not Allowed"))
|
||||||
|
|
||||||
validate_account_number(name, account_number, account.company)
|
account.validate_account_number(account_number)
|
||||||
if account_number:
|
if account_number:
|
||||||
frappe.db.set_value("Account", name, "account_number", account_number.strip())
|
frappe.db.set_value("Account", name, "account_number", account_number.strip())
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user