update_nsm_model in cost center on_trash()

This commit is contained in:
Nabin Hait
2011-09-27 10:38:41 +05:30
parent 8bb4ba4638
commit fe02f0602c
2 changed files with 67 additions and 47 deletions

View File

@@ -18,51 +18,57 @@ convert_to_lists = webnotes.conn.convert_to_lists
class DocType: class DocType:
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d,dl self.doc, self.doclist = d,dl
self.nsm_parent_field = 'parent_cost_center' self.nsm_parent_field = 'parent_cost_center'
def autoname(self): def autoname(self):
#company_abbr = sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0] self.doc.name = self.doc.cost_center_name + ' - ' + self.doc.company_abbr
self.doc.name = self.doc.cost_center_name + ' - ' + self.doc.company_abbr
#-------------------------------------------------------------------------
def get_abbr(self): def get_abbr(self):
abbr = sql("select abbr from tabCompany where company_name='%s'"%(self.doc.company_name))[0][0] or '' abbr = sql("select abbr from tabCompany where company_name='%s'"%(self.doc.company_name))[0][0] or ''
ret = { ret = {
'company_abbr' : abbr 'company_abbr' : abbr
} }
return ret return ret
def validate(self): #-------------------------------------------------------------------------
# Cost Center name must be unique def validate(self):
# --------------------------- """
if (self.doc.__islocal or (not self.doc.name)) and sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)): Cost Center name must be unique
msgprint("Cost Center Name already exists, please rename") """
raise Exception if (self.doc.__islocal or not self.doc.name) and sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)):
msgprint("Cost Center Name already exists, please rename", raise_exception=1)
check_acc_list = []
for d in getlist(self.doclist, 'budget_details'): check_acc_list = []
if [d.account, d.fiscal_year] in check_acc_list: for d in getlist(self.doclist, 'budget_details'):
msgprint("Account " + cstr(d.account) + "has been entered more than once for fiscal year " + cstr(d.fiscal_year)) if [d.account, d.fiscal_year] in check_acc_list:
raise Exception msgprint("Account " + cstr(d.account) + "has been entered more than once for fiscal year " + cstr(d.fiscal_year), raise_exception=1)
if [d.account, d.fiscal_year] not in check_acc_list: check_acc_list.append([d.account, d.fiscal_year]) else:
check_acc_list.append([d.account, d.fiscal_year])
def on_update(self):
# update Node Set Model #-------------------------------------------------------------------------
import webnotes def update_nsm_model(self):
import webnotes.utils.nestedset """
# update Node Set Model update Nested Set Model
webnotes.utils.nestedset.update_nsm(self) """
import webnotes.utils.nestedset
def check_if_child_exists(self): webnotes.utils.nestedset.update_nsm(self)
return sql("select name from `tabCost Center` where parent_cost_center = %s and docstatus != 2", self.doc.name, debug=0)
#-------------------------------------------------------------------------
# On Trash def on_update(self):
# -------- self.update_nsm_model()
def on_trash(self):
if self.check_if_child_exists(): def check_if_child_exists(self):
msgprint("Child exists for this cost center. You can not trash this account.", raise_exception=1) return sql("select name from `tabCost Center` where parent_cost_center = %s and docstatus != 2", self.doc.name)
# rebuild tree # On Trash
set(self.doc,'old_parent', '') #-------------------------------------------------------------------------
self.update_nsm_model() def on_trash(self):
if self.check_if_child_exists():
msgprint("Child exists for this cost center. You can not trash this account.", raise_exception=1)
# rebuild tree
set(self.doc,'old_parent', '')
self.update_nsm_model()

View File

@@ -360,3 +360,17 @@ def execute(patch_no):
reload_doc('hr', 'doctype', 'appraisal_detail') reload_doc('hr', 'doctype', 'appraisal_detail')
elif patch_no == 370: elif patch_no == 370:
sql("update `tabDocField` set `hidden` = 0 where fieldname = 'group_or_ledger' and parent = 'Cost Center'") sql("update `tabDocField` set `hidden` = 0 where fieldname = 'group_or_ledger' and parent = 'Cost Center'")
elif patch_no == 371:
comp = sql("select name from tabCompany where docstatus!=2")
fy = sql("select name from `tabFiscal Year` order by year_start_date asc")
for c in comp:
prev_fy = ''
for f in fy:
fy_obj = get_obj('Fiscal Year', f[0])
fy_obj.doc.past_year = prev_fy
fy_obj.doc.company = c[0]
fy_obj.doc.save()
fy_obj.repost()
prev_fy = f[0]
sql("commit")
sql("start transaction")