Merge pull request #3706 from neilLasrado/variant

Fetch Template Bom if no BOM is set against Item Variant in Production Order
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index 26af40a..93ce5e1 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -335,12 +335,15 @@
 	res = frappe.db.sql("""select stock_uom, description
 		from `tabItem` where (ifnull(end_of_life, "0000-00-00")="0000-00-00" or end_of_life > now())
 		and name=%s""", item, as_dict=1)
-
 	if not res:
 		return {}
 
 	res = res[0]
 	res["bom_no"] = frappe.db.get_value("BOM", filters={"item": item, "is_default": 1})
+	if not res["bom_no"]:
+		variant_of= frappe.db.get_value("Item", item, "variant_of")
+		if variant_of:
+			res["bom_no"] = frappe.db.get_value("BOM", filters={"item": variant_of, "is_default": 1})
 	return res
 
 @frappe.whitelist()
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 86a14d8..271abac 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -9,6 +9,7 @@
 
 from frappe.model.document import Document
 from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
+from erpnext.manufacturing.doctype.production_order.production_order import get_item_details
 
 class ProductionPlanningTool(Document):
 	def __init__(self, arg1, arg2=None):
@@ -27,16 +28,7 @@
 		return ret
 
 	def get_item_details(self, item_code):
-		""" Pull other item details from item master"""
-
-		item = frappe.db.sql("""select description, stock_uom, default_bom
-			from `tabItem` where name = %s""", item_code, as_dict =1)
-		ret = {
-			'description'	: item and item[0]['description'],
-			'stock_uom'		: item and item[0]['stock_uom'],
-			'bom_no'		: item and item[0]['default_bom']
-		}
-		return ret
+		return get_item_details(item_code)
 
 	def clear_so_table(self):
 		self.set('sales_orders', [])
@@ -142,15 +134,14 @@
 		self.clear_item_table()
 
 		for p in items:
-			item_details = frappe.db.sql("""select description, stock_uom, default_bom
-				from tabItem where name=%s""", p['item_code'])
+			item_details = get_item_details(p['item_code'])
 			pi = self.append('items', {})
 			pi.sales_order				= p['parent']
 			pi.warehouse				= p['warehouse']
 			pi.item_code				= p['item_code']
-			pi.description				= item_details and item_details[0][0] or ''
-			pi.stock_uom				= item_details and item_details[0][1] or ''
-			pi.bom_no					= item_details and item_details[0][2] or ''
+			pi.description				= item_details and item_details.description or ''
+			pi.stock_uom				= item_details and item_details.stock_uom or ''
+			pi.bom_no					= item_details and item_details.bom_no or ''
 			pi.so_pending_qty			= flt(p['pending_qty'])
 			pi.planned_qty				= flt(p['pending_qty'])