fix in delete doc

This commit is contained in:
Anand Doshi 2012-12-21 20:49:32 +05:30
parent 61ea1a63f4
commit dfbc02ed2a

View file

@ -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