[ 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
This commit is contained in:
Zarrar 2018-07-06 14:44:44 +05:30 committed by Nabin Hait
parent 8f2a0f3d79
commit 17705f932d
4 changed files with 9 additions and 7 deletions

View File

@ -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

View File

@ -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()

View File

@ -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) {

View File

@ -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("-")