Fixed Company Deletion
This commit is contained in:
parent
d75aef0a5d
commit
73e155cadc
@ -120,7 +120,7 @@ class DocType:
|
|||||||
# check if child exists
|
# check if child exists
|
||||||
# ==================================================================
|
# ==================================================================
|
||||||
def check_if_child_exists(self):
|
def check_if_child_exists(self):
|
||||||
return sql("select name from `tabAccount` where parent_account = %s and docstatus<2", self.doc.name)
|
return sql("select name from `tabAccount` where parent_account = %s and docstatus != 2", self.doc.name, debug=0)
|
||||||
|
|
||||||
# Update balance
|
# Update balance
|
||||||
# ==================================================================
|
# ==================================================================
|
||||||
@ -234,13 +234,13 @@ class DocType:
|
|||||||
if flt(self.get_curr_bal()) != 0:
|
if flt(self.get_curr_bal()) != 0:
|
||||||
msgprint("Account with existing balance can not be trashed", raise_exception=1)
|
msgprint("Account with existing balance can not be trashed", raise_exception=1)
|
||||||
if self.check_if_child_exists():
|
if self.check_if_child_exists():
|
||||||
msgprint("Child account exists for this account. You can not make trash this account.", raise_exception=1)
|
msgprint("Child account exists for this account. You can not trash this account.", raise_exception=1)
|
||||||
|
|
||||||
|
|
||||||
# get current year balance
|
# get current year balance
|
||||||
# ==================================================================
|
# ==================================================================
|
||||||
def get_curr_bal(self):
|
def get_curr_bal(self):
|
||||||
bal = sql("select balance from `tabAccount Balance` where period = '%s' and parent = '%s'" % (get_defaults()['fiscal_year'], self.doc.name))
|
bal = sql("select balance from `tabAccount Balance` where period = '%s' and parent = '%s'" % (get_defaults()['fiscal_year'], self.doc.name),debug=0)
|
||||||
return bal and flt(bal[0][0]) or 0
|
return bal and flt(bal[0][0]) or 0
|
||||||
|
|
||||||
# On Trash
|
# On Trash
|
||||||
@ -252,6 +252,9 @@ class DocType:
|
|||||||
set(self.doc,'old_parent', '')
|
set(self.doc,'old_parent', '')
|
||||||
self.update_nsm_model()
|
self.update_nsm_model()
|
||||||
|
|
||||||
|
#delete Account Balance
|
||||||
|
sql("delete from `tabAccount Balance` where account = %s", self.doc.name)
|
||||||
|
|
||||||
# On restore
|
# On restore
|
||||||
# ==================================================================
|
# ==================================================================
|
||||||
def on_restore(self):
|
def on_restore(self):
|
||||||
|
@ -26,7 +26,6 @@ class DocType:
|
|||||||
#company_abbr = sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
#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 = {
|
||||||
@ -35,10 +34,8 @@ class DocType:
|
|||||||
return cstr(ret)
|
return cstr(ret)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
|
||||||
# Cost Center name must be unique
|
# Cost Center name must be unique
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
||||||
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)):
|
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")
|
msgprint("Cost Center Name already exists, please rename")
|
||||||
raise Exception
|
raise Exception
|
||||||
@ -56,3 +53,16 @@ class DocType:
|
|||||||
import webnotes.utils.nestedset
|
import webnotes.utils.nestedset
|
||||||
# update Node Set Model
|
# update Node Set Model
|
||||||
webnotes.utils.nestedset.update_nsm(self)
|
webnotes.utils.nestedset.update_nsm(self)
|
||||||
|
|
||||||
|
def check_if_child_exists(self):
|
||||||
|
return sql("select name from `tabCost Center` where parent_cost_center = %s and docstatus != 2", self.doc.name, debug=1)
|
||||||
|
|
||||||
|
# On Trash
|
||||||
|
# --------
|
||||||
|
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()
|
||||||
|
@ -202,17 +202,35 @@ class DocType:
|
|||||||
|
|
||||||
# Trash accounts and cost centers for this company
|
# Trash accounts and cost centers for this company
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
|
#def on_trash1(self):
|
||||||
|
# acc = sql("select name from tabAccount where company = '%s' and docstatus != 2 order by lft desc, rgt desc limit 2" % self.doc.name, debug=1)
|
||||||
|
# for each in acc:
|
||||||
|
# get_obj('Account', each[0]).on_trash()
|
||||||
|
|
||||||
|
# cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus != 2" % self.doc.name)
|
||||||
|
# for each in cc:
|
||||||
|
# get_obj('Cost Center', each[0]).on_trash()
|
||||||
|
|
||||||
|
# msgprint("Company trashed. All the accounts and cost centers related to this company also trashed. You can restore it anytime from Setup -> Manage Trash")
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
acc = sql("select name from tabAccount where company = '%s' and docstatus = 1" % self.doc.name)
|
rec = sql("SELECT sum(ab.opening), sum(ab.balance), sum(ab.debit), sum(ab.credit) FROM `tabAccount Balance` ab, `tabAccount` a WHERE ab.account = a.name and a.company = %s", self.doc.name)
|
||||||
for each in acc:
|
if rec[0][0] == 0 and rec[0][1] == 0 and rec[0][2] == 0 and rec[0][3] == 0:
|
||||||
get_obj('Account', each[0]).on_trash()
|
#delete tabAccount Balance
|
||||||
|
sql("delete ab.* from `tabAccount Balance` ab, `tabAccount` a where ab.account = a.name and a.company = %s", self.doc.name)
|
||||||
|
#delete tabAccount
|
||||||
|
sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name)
|
||||||
|
|
||||||
cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus = 1" % self.doc.name)
|
#delete cost center child table - budget detail
|
||||||
for each in cc:
|
sql("delete bd.* from `tabBudget Detail` bd, `tabCost Center` cc where bd.parent = cc.name and cc.company_name = %s", self.doc.name)
|
||||||
get_obj('Cost Center', each[0]).on_trash()
|
#delete cost center
|
||||||
|
sql("delete from `tabCost Center` WHERE company_name = %s order by lft desc, rgt desc", self.doc.name)
|
||||||
|
|
||||||
msgprint("Company trashed. All the accounts and cost centers related to this company also trashed. You can restore it anytime from Setup -> Manage Trash")
|
#update value as blank for tabDefaultValue defkey=company
|
||||||
|
sql("update `tabDefaultValue` set defvalue = '' where defkey='company' and defvalue = %s", self.doc.name)
|
||||||
|
|
||||||
|
#update value as blank for tabSingles Manage Account
|
||||||
|
sql("update `tabSingles` set value = '' where doctype='Manage Account' and field = 'default_company' and value = %s", self.doc.name)
|
||||||
|
|
||||||
# Restore accounts and cost centers for this company
|
# Restore accounts and cost centers for this company
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user