fix: Display message to delete linked invoices in the draft state
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 9367609..c2107b6 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -241,7 +241,7 @@
 		# Checks Sales Invoice
 		submit_rv = frappe.db.sql_list("""select t1.name
 			from `tabSales Invoice` t1,`tabSales Invoice Item` t2
-			where t1.name = t2.parent and t2.sales_order = %s and t1.docstatus < 2""",
+			where t1.name = t2.parent and t2.sales_order = %s and t1.docstatus = 1""",
 			self.name)
 
 		if submit_rv:
@@ -249,6 +249,16 @@
 			frappe.throw(_("Sales Invoice {0} must be cancelled before cancelling this Sales Order")
 				.format(", ".join(submit_rv)))
 
+		draft_rv = frappe.db.sql_list("""select t1.name
+			from `tabSales Invoice` t1,`tabSales Invoice Item` t2
+			where t1.name = t2.parent and t2.sales_order = %s and t1.docstatus = 0""",
+			self.name)
+
+		if draft_rv:
+			draft_rv = [get_link_to_form("Sales Invoice", si) for si in draft_rv]
+			frappe.throw(_("Sales Invoice {0} must be deleted before cancelling this Sales Order")
+				.format(", ".join(draft_rv)))
+
 		#check maintenance schedule
 		submit_ms = frappe.db.sql_list("""
 			select t1.name