diff --git a/webnotes/db.py b/webnotes/db.py index ecf55c3c7f..537911429c 100644 --- a/webnotes/db.py +++ b/webnotes/db.py @@ -330,7 +330,11 @@ class Database: return self.get_values_from_table(fields, filters, doctype, as_dict, debug) except Exception, e: if ignore and e.args[0] in (1146, 1054): + # table or column not found, return None return None + elif (not ignore) and e.args[0]==1146: + # table not found, look in singles + pass else: raise e diff --git a/webnotes/model/utils.py b/webnotes/model/utils.py index aee746d834..e0ad09dfc5 100644 --- a/webnotes/model/utils.py +++ b/webnotes/model/utils.py @@ -212,18 +212,19 @@ def check_if_doc_is_linked(dt, dn, method="Delete"): """ from webnotes.model.rename_doc import get_link_fields link_fields = get_link_fields(dt) - link_fields = [[lf['parent'], lf['fieldname']] for lf in link_fields] + link_fields = [[lf['parent'], lf['fieldname'], lf['issingle']] for lf in link_fields] - for link_dt, link_field in link_fields: - item = webnotes.conn.get_value(link_dt, {link_field:dn}, ["name", "parent", "parenttype", - "docstatus"], as_dict=True) + for link_dt, link_field, issingle in link_fields: + if not issingle: + item = webnotes.conn.get_value(link_dt, {link_field:dn}, + ["name", "parent", "parenttype", "docstatus"], as_dict=True) - if item and item.parent != dn and (method=="Delete" or - (method=="Cancel" and item.docstatus==1)): - webnotes.msgprint(method + " " + _("Error") + ":"+\ - ("%s (%s) " % (dn, dt)) + _("is linked in") + (" %s (%s)") % - (item.parent or item.name, item.parent and item.parenttype or link_dt), - raise_exception=LinkExistsError) + if item and item.parent != dn and (method=="Delete" or + (method=="Cancel" and item.docstatus==1)): + webnotes.msgprint(method + " " + _("Error") + ":"+\ + ("%s (%s) " % (dn, dt)) + _("is linked in") + (" %s (%s)") % + (item.parent or item.name, item.parent and item.parenttype or link_dt), + raise_exception=LinkExistsError) def set_default(doc, key): if not doc.is_default: