mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
Fixed Company Deletion
This commit is contained in:
@@ -120,7 +120,7 @@ class DocType:
|
||||
# check if child exists
|
||||
# ==================================================================
|
||||
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
|
||||
# ==================================================================
|
||||
@@ -234,24 +234,27 @@ class DocType:
|
||||
if flt(self.get_curr_bal()) != 0:
|
||||
msgprint("Account with existing balance can not be trashed", raise_exception=1)
|
||||
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
|
||||
# ==================================================================
|
||||
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
|
||||
|
||||
# On Trash
|
||||
# ==================================================================
|
||||
def on_trash(self):
|
||||
# Check balance before trash
|
||||
self.check_balance_before_trash()
|
||||
self.check_balance_before_trash()
|
||||
# rebuild tree
|
||||
set(self.doc,'old_parent', '')
|
||||
self.update_nsm_model()
|
||||
|
||||
#delete Account Balance
|
||||
sql("delete from `tabAccount Balance` where account = %s", self.doc.name)
|
||||
|
||||
# On restore
|
||||
# ==================================================================
|
||||
def on_restore(self):
|
||||
|
||||
@@ -24,8 +24,7 @@ class DocType:
|
||||
|
||||
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):
|
||||
abbr = sql("select abbr from tabCompany where company_name='%s'"%(self.doc.company_name))[0][0] or ''
|
||||
@@ -35,10 +34,8 @@ class DocType:
|
||||
return cstr(ret)
|
||||
|
||||
def validate(self):
|
||||
|
||||
# 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)):
|
||||
msgprint("Cost Center Name already exists, please rename")
|
||||
raise Exception
|
||||
@@ -55,4 +52,17 @@ class DocType:
|
||||
import webnotes
|
||||
import webnotes.utils.nestedset
|
||||
# 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()
|
||||
|
||||
Reference in New Issue
Block a user