fix: Remove QI link on cancel wherever same QI name exists
diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py
index b30d48d..2084e3f 100644
--- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py
+++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py
@@ -70,9 +70,12 @@
 
 			if self.reference_type and self.reference_name:
 				conditions = ""
-				if self.batch_no:
+				if self.batch_no and self.docstatus == 1:
 					conditions += " and t1.batch_no = '%s'"%(self.batch_no)
 
+				if self.docstatus == 2: # if cancel, then remove qi link wherever same name
+					conditions += " and t1.quality_inspection = '%s'"%(self.name)
+
 				frappe.db.sql("""
 					UPDATE
 						`tab{child_doc}` t1, `tab{parent_doc}` t2