From 17705f932d3440dc4f0a06d80302aefeaa3dc96d Mon Sep 17 00:00:00 2001 From: Zarrar Date: Fri, 6 Jul 2018 14:44:44 +0530 Subject: [PATCH] [ 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 --- erpnext/accounts/doctype/account/account.py | 4 ++-- erpnext/accounts/doctype/cost_center/cost_center.py | 4 ++-- erpnext/accounts/doctype/cost_center/cost_center_tree.js | 4 +++- erpnext/accounts/utils.py | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index 3e1da66007..b92e423249 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -20,8 +20,8 @@ class Account(NestedSet): 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 af9c8f7704..5d57d2bc93 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.py +++ b/erpnext/accounts/doctype/cost_center/cost_center.py @@ -13,8 +13,8 @@ class CostCenter(NestedSet): 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 be48d7020d..16d9734432 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 @@ frappe.treeview_settings["Cost Center"] = { 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 f5df4c4310..61280948c6 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -784,7 +784,7 @@ def update_number_field(doctype_name, name, field_name, field_value, company): 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 @@ def validate_field_number(doctype_name, name, field_value, company, field_name): 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("-")