Added on_trash function for checking link of the master
This commit is contained in:
parent
902b14592f
commit
a3eee118fc
@ -34,26 +34,32 @@ convert_to_lists = webnotes.conn.convert_to_lists
|
|||||||
|
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
self.doclist = doclist
|
self.doclist = doclist
|
||||||
self.nsm_parent_field = 'parent_customer_group';
|
self.nsm_parent_field = 'parent_customer_group';
|
||||||
|
|
||||||
|
|
||||||
# update Node Set Model
|
# update Node Set Model
|
||||||
def update_nsm_model(self):
|
def update_nsm_model(self):
|
||||||
import webnotes
|
import webnotes
|
||||||
import webnotes.utils.nestedset
|
import webnotes.utils.nestedset
|
||||||
webnotes.utils.nestedset.update_nsm(self)
|
webnotes.utils.nestedset.update_nsm(self)
|
||||||
|
|
||||||
# ON UPDATE
|
# ON UPDATE
|
||||||
#--------------------------------------
|
#--------------------------------------
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
# update nsm
|
# update nsm
|
||||||
self.update_nsm_model()
|
self.update_nsm_model()
|
||||||
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
if sql("select name from `tabCustomer Group` where name = %s and docstatus = 2", (self.doc.customer_group_name)):
|
||||||
|
msgprint("""Another %s record is trashed.
|
||||||
|
To untrash please go to Setup & click on Trash."""%(self.doc.customer_group_name), raise_exception = 1)
|
||||||
|
|
||||||
if sql("select name from `tabCustomer Group` where name = %s and docstatus = 2", (self.doc.customer_group_name)):
|
def on_trash(self):
|
||||||
msgprint("%s record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.customer_group_name), raise_exception = 1)
|
cust = sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s", self.doc.name)
|
||||||
|
if cust:
|
||||||
|
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)
|
||||||
|
@ -60,4 +60,10 @@ class DocType:
|
|||||||
r = sql("select name from `tabItem Group` where name = '%s' and docstatus = 2"%(self.doc.item_group_name))
|
r = sql("select name from `tabItem Group` where name = '%s' and docstatus = 2"%(self.doc.item_group_name))
|
||||||
if r:
|
if r:
|
||||||
msgprint("'%s' record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.item_group_name))
|
msgprint("'%s' record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.item_group_name))
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
def on_trash(self):
|
||||||
|
ig = sql("select name from `tabItem` where ifnull(item_group, '') = %s", self.doc.name)
|
||||||
|
if ig:
|
||||||
|
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)
|
||||||
|
@ -74,4 +74,11 @@ class DocType:
|
|||||||
for d in getlist(self.doclist, 'target_details'):
|
for d in getlist(self.doclist, 'target_details'):
|
||||||
if not flt(d.target_qty) and not flt(d.target_amount):
|
if not flt(d.target_qty) and not flt(d.target_amount):
|
||||||
msgprint("Either target qty or target amount is mandatory.")
|
msgprint("Either target qty or target amount is mandatory.")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
|
def on_trash(self):
|
||||||
|
terr = sql("select name from `tabCustomer` where ifnull(territory, '') = %s", self.doc.name)
|
||||||
|
if terr:
|
||||||
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user