fix: abbreviation issue on renaming cost center

(cherry picked from commit af21a11e1e)
This commit is contained in:
Nabin Hait
2022-09-15 12:09:18 +05:30
committed by Mergify
parent af5fb78fe2
commit f752822bb3
3 changed files with 8 additions and 10 deletions

View File

@@ -1037,7 +1037,7 @@ def update_cost_center(docname, cost_center_name, cost_center_number, company, m
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 validate_field_number(doctype_name, docname, number_value, company, field_na
)
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)