Allow manufacturing order from SO with Packed Items that contains BOM's (#11947)

diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index d45fbde..91d7eb6 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -53,10 +53,13 @@
 		if self.sales_order:
 			so = frappe.db.sql("""
 				select so.name, so_item.delivery_date, so.project
-				from `tabSales Order` so, `tabSales Order Item` so_item
-				where so.name=%s and so.name=so_item.parent
-					and so.docstatus = 1 and so_item.item_code=%s
-			""", (self.sales_order, self.production_item), as_dict=1)
+				from `tabSales Order` so
+				inner join `tabSales Order Item` so_item on so_item.parent = so.name
+				left join `tabProduct Bundle Item` pk_item on so_item.item_code = pk_item.parent
+				where so.name=%s and so.docstatus = 1 and (
+					so_item.item_code=%s or
+					pk_item.item_code=%s )
+			""", (self.sales_order, self.production_item, self.production_item), as_dict=1)
 
 			if len(so):
 				if not self.expected_delivery_date: