From 22aa17bcce2d41050b4e0f4ca8d77f330f645f5f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 29 Feb 2012 10:44:27 +0530 Subject: [PATCH 1/2] changes in trend analyzer query --- .../analysis/search_criteria/trend_analyzer/trend_analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/analysis/search_criteria/trend_analyzer/trend_analyzer.py b/erpnext/analysis/search_criteria/trend_analyzer/trend_analyzer.py index ad5718154b..2198204894 100644 --- a/erpnext/analysis/search_criteria/trend_analyzer/trend_analyzer.py +++ b/erpnext/analysis/search_criteria/trend_analyzer/trend_analyzer.py @@ -107,7 +107,7 @@ if item or based_on == 'Item': # Item Group if item_group or based_on == 'Item Group': add_tab += ' ,`tabItem` t3, `tabItem Group` t4 ' - add_cond += ' AND t3.name = t2.item_code AND t3.item_group = t4.name and (t4.name = "%s" or t4.name IN (SELECT t5.name FROM `tabItem Group` t5,`tabItem Group` t6 WHERE t5.lft BETWEEN t6.lft and t6.rgt and t5.docstatus !=2 and ifnull(t5.is_group,"No") = "No" and t6.name = "%s"))' % (based_on != 'Item Group' and item_group or '%(value)s', based_on != 'Item Group' and item_group or '%(value)s') + add_cond += ' AND t3.name = t2.item_code AND t3.item_group = t4.name and (t4.name = "%s" or t4.name IN (SELECT t5.name FROM `tabItem Group` t5,`tabItem Group` t6 WHERE t5.lft BETWEEN t6.lft and t6.rgt and t5.docstatus !=2 and t6.name = "%s"))' % (based_on != 'Item Group' and item_group or '%(value)s', based_on != 'Item Group' and item_group or '%(value)s') # Customer if customer or based_on == 'Customer': From a3eee118fcadb7627a7083f800892e4875b2ec3a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 29 Feb 2012 11:24:55 +0530 Subject: [PATCH 2/2] Added on_trash function for checking link of the master --- .../doctype/customer_group/customer_group.py | 40 +++++++++++-------- .../setup/doctype/item_group/item_group.py | 8 +++- erpnext/setup/doctype/territory/territory.py | 9 ++++- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/erpnext/setup/doctype/customer_group/customer_group.py b/erpnext/setup/doctype/customer_group/customer_group.py index 30885eb7b8..cc4a9e0b57 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.py +++ b/erpnext/setup/doctype/customer_group/customer_group.py @@ -34,26 +34,32 @@ convert_to_lists = webnotes.conn.convert_to_lists class DocType: - def __init__(self, doc, doclist=[]): - self.doc = doc - self.doclist = doclist - self.nsm_parent_field = 'parent_customer_group'; + def __init__(self, doc, doclist=[]): + self.doc = doc + self.doclist = doclist + self.nsm_parent_field = 'parent_customer_group'; - # update Node Set Model - def update_nsm_model(self): - import webnotes - import webnotes.utils.nestedset - webnotes.utils.nestedset.update_nsm(self) + # update Node Set Model + def update_nsm_model(self): + import webnotes + import webnotes.utils.nestedset + webnotes.utils.nestedset.update_nsm(self) - # ON UPDATE - #-------------------------------------- - def on_update(self): - # update nsm - self.update_nsm_model() + # ON UPDATE + #-------------------------------------- + def on_update(self): + # update nsm + 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)): - msgprint("%s record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.customer_group_name), raise_exception = 1) + def on_trash(self): + 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) diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index ba49117429..a3ed364c7e 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -60,4 +60,10 @@ class DocType: r = sql("select name from `tabItem Group` where name = '%s' and docstatus = 2"%(self.doc.item_group_name)) if r: msgprint("'%s' record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.item_group_name)) - raise Exception \ No newline at end of file + 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) diff --git a/erpnext/setup/doctype/territory/territory.py b/erpnext/setup/doctype/territory/territory.py index 461b447aa7..8017ad5757 100644 --- a/erpnext/setup/doctype/territory/territory.py +++ b/erpnext/setup/doctype/territory/territory.py @@ -74,4 +74,11 @@ class DocType: for d in getlist(self.doclist, 'target_details'): if not flt(d.target_qty) and not flt(d.target_amount): msgprint("Either target qty or target amount is mandatory.") - raise Exception \ No newline at end of file + 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)