Merge pull request #32222 from nabinhait/cost-center-renaming
fix: abbreviation issue on renaming cost center
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 2610c86..9dff116 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -37,7 +37,7 @@
def autoname(self):
from erpnext.accounts.utils import get_autoname_with_number
- self.name = get_autoname_with_number(self.account_number, self.account_name, None, self.company)
+ self.name = get_autoname_with_number(self.account_number, self.account_name, self.company)
def validate(self):
from erpnext.accounts.utils import validate_field_number
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py
index 31055c3..e8b34bb 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.py
+++ b/erpnext/accounts/doctype/cost_center/cost_center.py
@@ -16,7 +16,7 @@
from erpnext.accounts.utils import get_autoname_with_number
self.name = get_autoname_with_number(
- self.cost_center_number, self.cost_center_name, None, self.company
+ self.cost_center_number, self.cost_center_name, self.company
)
def validate(self):
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index f61e8ac..c5eb7d8 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -1037,7 +1037,7 @@
frappe.db.set_value("Cost Center", docname, "cost_center_name", cost_center_name.strip())
- new_name = get_autoname_with_number(cost_center_number, cost_center_name, docname, company)
+ new_name = get_autoname_with_number(cost_center_number, cost_center_name, company)
if docname != new_name:
frappe.rename_doc("Cost Center", docname, new_name, force=1, merge=merge)
return new_name
@@ -1060,16 +1060,14 @@
)
-def get_autoname_with_number(number_value, doc_title, name, company):
+def get_autoname_with_number(number_value, doc_title, company):
"""append title with prefix as number and suffix as company's abbreviation separated by '-'"""
- if name:
- name_split = name.split("-")
- parts = [doc_title.strip(), name_split[len(name_split) - 1].strip()]
- else:
- abbr = frappe.get_cached_value("Company", company, ["abbr"], as_dict=True)
- parts = [doc_title.strip(), abbr.abbr]
+ company_abbr = frappe.get_cached_value("Company", company, "abbr")
+ parts = [doc_title.strip(), company_abbr]
+
if cstr(number_value).strip():
parts.insert(0, cstr(number_value).strip())
+
return " - ".join(parts)