From e10900115edc2adbfcda8bf240bbd36f64e0e17f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 16 Sep 2011 15:50:45 +0530 Subject: [PATCH] updated company on_trash function --- erpnext/setup/doctype/company/company.py | 38 +++++++----------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index a2e333d41c3..45b4973f9c8 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -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 # ---------