diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index ac112ddaf3..b452073467 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -193,13 +193,20 @@ def check_if_doc_is_linked(doc, method="Delete"): # don't check for communication and todo! continue - 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 + if not item: + continue + elif (method != "Delete" or item.docstatus == 2) and (method != "Cancel" or item.docstatus != 1): + # don't raise exception if not + # linked to a non-cancelled doc when deleting or to a submitted doc when cancelling + continue + elif link_dt == doc.doctype and (item.parent or item.name) == doc.name: + # don't raise exception if not + # linked to same item or doc having same name as the item + continue + else: reference_docname = item.parent or item.name raise_link_exists_exception(doc, linked_doctype, reference_docname) + else: if frappe.db.get_value(link_dt, None, link_field) == doc.name: raise_link_exists_exception(doc, link_dt, link_dt)