[ Minor ] Cost Center Number field added in field's dialog (#14781)
* cost center number field when creating new
added field in the tree's dialog, necessary changes in the autoname function
* rename function's name appropriately
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 3e1da66..b92e423 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -20,8 +20,8 @@
self.set_onload("can_freeze_account", True)
def autoname(self):
- from erpnext.accounts.utils import get_doc_name_autoname
- self.name = get_doc_name_autoname(self.account_number, self.account_name, None, self.company)
+ from erpnext.accounts.utils import get_autoname_with_number
+ self.name = get_autoname_with_number(self.account_number, self.account_name, None, 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 af9c8f7..5d57d2b 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.py
+++ b/erpnext/accounts/doctype/cost_center/cost_center.py
@@ -13,8 +13,8 @@
nsm_parent_field = 'parent_cost_center'
def autoname(self):
- self.name = self.cost_center_name.strip() + ' - ' + \
- frappe.db.get_value("Company", self.company, "abbr")
+ 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)
def validate(self):
self.validate_mandatory()
diff --git a/erpnext/accounts/doctype/cost_center/cost_center_tree.js b/erpnext/accounts/doctype/cost_center/cost_center_tree.js
index be48d70..16d9734 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center_tree.js
+++ b/erpnext/accounts/doctype/cost_center/cost_center_tree.js
@@ -21,7 +21,9 @@
fields:[
{fieldtype:'Data', fieldname:'cost_center_name', label:__('New Cost Center Name'), reqd:true},
{fieldtype:'Check', fieldname:'is_group', label:__('Is Group'),
- description:__('Further cost centers can be made under Groups but entries can be made against non-Groups')}
+ description:__('Further cost centers can be made under Groups but entries can be made against non-Groups')},
+ {fieldtype:'Data', fieldname:'cost_center_number', label:__('Cost Center Number'),
+ description: __("Number of new Cost Center, it will be included in the cost center name as a prefix")}
],
ignore_fields:["parent_cost_center"],
onload: function(treeview) {
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index f5df4c4..6128094 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -784,7 +784,7 @@
frappe.db.set_value(doctype_name, name, frappe.scrub(doctype_name)+"_name", doc_title)
- new_name = get_doc_name_autoname(field_value, doc_title, name, company)
+ new_name = get_autoname_with_number(field_value, doc_title, name, company)
if name != new_name:
frappe.rename_doc(doctype_name, name, new_name)
@@ -803,7 +803,7 @@
frappe.throw(_("{0} Number {1} already used in account {2}")
.format(doctype_name, field_value, doctype_with_same_number))
-def get_doc_name_autoname(field_value, doc_title, name, company):
+def get_autoname_with_number(number_value, doc_title, name, company):
''' append title with prefix as number and suffix as company's abbreviation separated by '-' '''
if name:
name_split=name.split("-")