From f9fd3945aeab4ab079a9d99d73df4d9109ad2f25 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 11 Apr 2016 11:05:43 +0530 Subject: [PATCH] [fix] Ignore current document while checking linked docs on deletion --- frappe/model/delete_doc.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index e467e16667..23c50604bd 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -158,15 +158,14 @@ def check_if_doc_is_linked(doc, method="Delete"): if not issingle: item = frappe.db.get_value(link_dt, {link_field:doc.name}, ["name", "parent", "parenttype", "docstatus"], as_dict=True) - - if item and item.parent != doc.name and ((method=="Delete" and item.docstatus<2) or - (method=="Cancel" and item.docstatus==1)): + if item and ((item.parent or item.name) != doc.name) \ + and ((method=="Delete" and item.docstatus<2) or (method=="Cancel" and item.docstatus==1)): # raise exception only if # linked to an non-cancelled doc when deleting # or linked to a submitted doc when cancelling - frappe.throw(_("Cannot delete or cancel because {0} {1} is linked with {2} {3}").format(doc.doctype, - doc.name, item.parenttype if item.parent else link_dt, item.parent or item.name), - frappe.LinkExistsError) + frappe.throw(_("Cannot delete or cancel because {0} {1} is linked with {2} {3}") + .format(doc.doctype, doc.name, item.parenttype if item.parent else link_dt, + item.parent or item.name), frappe.LinkExistsError) def check_if_doc_is_dynamically_linked(doc, method="Delete"): '''Raise `frappe.LinkExistsError` if the document is dynamically linked'''