From dfbc02ed2a2be94766a8d1c87052199e2a0430fb Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 21 Dec 2012 20:49:32 +0530 Subject: [PATCH] fix in delete doc --- webnotes/model/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webnotes/model/__init__.py b/webnotes/model/__init__.py index 7cbd28e879..46ad008f30 100644 --- a/webnotes/model/__init__.py +++ b/webnotes/model/__init__.py @@ -66,7 +66,12 @@ def check_if_doc_is_linked(dt, dn): else: item = None try: - item = sql("select name, parent, parenttype from `tab%s` where `%s`='%s' and docstatus!=2 and `%s`!=parent limit 1" % (link_dt, link_field, dn, link_field)) + # (ifnull(parent, '')='' or `%s`!=`parent`) + # this condition ensures that it allows deletion when child table field references parent + + item = sql("select name, parent, parenttype from `tab%s` where `%s`='%s' and docstatus!=2 and (ifnull(parent, '')='' or `%s`!=`parent`) \ + limit 1" % (link_dt, link_field, dn, link_field), debug=1) + except Exception, e: if e.args[0]==1146: pass else: raise e