on_trash modified for item group, territory, customer group, and sales person
This commit is contained in:
parent
c68635d70a
commit
d9742a6a58
@ -136,7 +136,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, debug=0)
|
return sql("select name from `tabAccount` where parent_account = %s and docstatus != 2", self.doc.name)
|
||||||
|
|
||||||
# Update balance
|
# Update balance
|
||||||
# ==================================================================
|
# ==================================================================
|
||||||
|
@ -60,6 +60,15 @@ class DocType:
|
|||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
cust = sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s", self.doc.name)
|
cust = sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s", self.doc.name)
|
||||||
|
cust = [d[0] for d in cust]
|
||||||
|
|
||||||
if cust:
|
if cust:
|
||||||
msgprint("""Customer Group: %s can not be trashed/deleted because it is used in customer: %s.
|
msgprint("""Customer Group: %s can not be trashed/deleted because it is used in customer: %s.
|
||||||
To trash/delete this, remove/change customer group in customer master""" % (self.doc.name, cust[0][0] or ''), raise_exception=1)
|
To trash/delete this, remove/change customer group in customer master""" % (self.doc.name, cust or ''), raise_exception=1)
|
||||||
|
|
||||||
|
if sql("select name from `tabCustomer Group` where parent_customer_group = %s and docstatus != 2", self.doc.name):
|
||||||
|
msgprint("Child customer group exists for this customer group. You can not trash/cancel/delete this customer group.", raise_exception=1)
|
||||||
|
|
||||||
|
# rebuild tree
|
||||||
|
webnotes.conn.set(self.doc,'old_parent', '')
|
||||||
|
self.update_nsm_model()
|
@ -63,7 +63,17 @@ class DocType:
|
|||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
ig = sql("select name from `tabItem` where ifnull(item_group, '') = %s", self.doc.name)
|
item = sql("select name from `tabItem` where ifnull(item_group, '') = %s", self.doc.name)
|
||||||
|
item = [d[0] for d in item]
|
||||||
|
|
||||||
if ig:
|
if ig:
|
||||||
msgprint("""Item Group: %s can not be trashed/deleted because it is used in item: %s.
|
msgprint("""Item Group: %s can not be trashed/deleted because it is used in item: %s.
|
||||||
To trash/delete this, remove/change item group in item master""" % (self.doc.name, ig[0][0] or ''), raise_exception=1)
|
To trash/delete this, remove/change item group in item master""" % (self.doc.name, item or ''), raise_exception=1)
|
||||||
|
|
||||||
|
if sql("select name from `tabItem Group` where parent_item_group = %s and docstatus != 2", self.doc.name):
|
||||||
|
msgprint("Child item group exists for this item group. You can not trash/cancel/delete this item group.", raise_exception=1)
|
||||||
|
|
||||||
|
|
||||||
|
# rebuild tree
|
||||||
|
set(self.doc,'old_parent', '')
|
||||||
|
self.update_nsm_model()
|
@ -21,7 +21,7 @@ from webnotes.model.doc import Document
|
|||||||
from webnotes.model.doclist import getlist
|
from webnotes.model.doclist import getlist
|
||||||
from webnotes.model.code import get_obj
|
from webnotes.model.code import get_obj
|
||||||
from webnotes import session, form, is_testing, msgprint, errprint
|
from webnotes import session, form, is_testing, msgprint, errprint
|
||||||
from webnotes.utils import flt
|
from webnotes.utils import flt, cstr
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
convert_to_lists = webnotes.conn.convert_to_lists
|
convert_to_lists = webnotes.conn.convert_to_lists
|
||||||
@ -78,3 +78,18 @@ class DocType:
|
|||||||
d.is_sales_person = 1
|
d.is_sales_person = 1
|
||||||
|
|
||||||
d.save(new = (not d.name))
|
d.save(new = (not d.name))
|
||||||
|
|
||||||
|
|
||||||
|
def on_trash(self):
|
||||||
|
st = sql("select parent, parenttype from `tabSales Team` where ifnull(sales_person, '') = %s and docstatus != 2", self.doc.name)
|
||||||
|
st = [(d[1] + ' : ' + d[0]) for d in st]
|
||||||
|
if st:
|
||||||
|
msgprint("""Sales Person: %s can not be trashed/deleted because it is used in %s.
|
||||||
|
To trash/delete this, remove/change sales person in %s""" % (self.doc.name, st or '', st or ''), raise_exception=1)
|
||||||
|
|
||||||
|
if sql("select name from `tabSales Person` where parent_sales_person = %s and docstatus != 2", self.doc.name):
|
||||||
|
msgprint("Child sales person exists for this sales person. You can not trash/cancel this sales person.", raise_exception=1)
|
||||||
|
|
||||||
|
# rebuild tree
|
||||||
|
webnotes.conn.set(self.doc,'old_parent', '')
|
||||||
|
self.update_nsm_model()
|
||||||
|
@ -78,7 +78,17 @@ class DocType:
|
|||||||
|
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
terr = sql("select name from `tabCustomer` where ifnull(territory, '') = %s", self.doc.name)
|
cust = sql("select name from `tabCustomer` where ifnull(territory, '') = %s", self.doc.name)
|
||||||
if terr:
|
cust = [d[0] for d in cust]
|
||||||
msgprint("""Territory: %s can not be trashed/deleted because it is used in territory: %s.
|
|
||||||
To trash/delete this, remove/change territory in customer master""" % (self.doc.name, terr[0][0] or ''), raise_exception=1)
|
if cust:
|
||||||
|
msgprint("""Territory: %s can not be trashed/deleted because it is used in customer: %s.
|
||||||
|
To trash/delete this, remove/change territory in customer master""" % (self.doc.name, cust or ''), raise_exception=1)
|
||||||
|
|
||||||
|
|
||||||
|
if sql("select name from `tabTerritory` where parent_territory = %s and docstatus != 2", self.doc.name):
|
||||||
|
msgprint("Child territory exists for this territory. You can not trash/cancel/delete this territory.", raise_exception=1)
|
||||||
|
|
||||||
|
# rebuild tree
|
||||||
|
set(self.doc,'old_parent', '')
|
||||||
|
self.update_nsm_model()
|
Loading…
x
Reference in New Issue
Block a user