updated company on_trash function

This commit is contained in:
Nabin Hait 2011-09-16 15:50:45 +05:30
parent 741743510b
commit e10900115e

View File

@ -200,24 +200,20 @@ class DocType:
if not cc:
self.create_default_cost_center()
# 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):
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)
if rec[0][0] == 0 and rec[0][1] == 0 and rec[0][2] == 0 and rec[0][3] == 0:
"""
Trash accounts and cost centers for this company if no gl entry exists
"""
rec = sql("SELECT name from `tabGL Entry` where ifnull(is_cancelled, 'No') = 'No' and company = %s", self.doc.name)
if not rec:
# delete gl entry
sql("delete from `tabGL Entry` where company = %s", self.doc.name)
#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)
@ -232,18 +228,6 @@ class DocType:
#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
# ---------------------------------------------------
def on_restore(self):
acc = sql("select name from tabAccount where company = '%s' and docstatus = 2" % self.doc.name)
for each in acc:
get_obj('Account', each[0]).on_restore()
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_restore()
msgprint("Company restored. All the accounts and cost centers related to this company also restored.")
# on rename
# ---------