code changes for single stock entry
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index f49f110..f84feab 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -284,7 +284,8 @@
 			}
 			,
 			callback: function(r) {
-				frappe.set_route("List", "Stock Entry", "List",{"purchase_order":r.message,"doc_status":0})
+				var doclist = frappe.model.sync(r.message);
+				frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
 			}
 		});
 	},
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index a021690..e78d4b7 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -435,30 +435,29 @@
 		item_wh = frappe._dict(frappe.db.sql("""select item_code, description
 										from `tabItem` where name in ({0})""".
 										format(", ".join(["%s"] * len(item_code_list))), item_code_list))
+		stock_entry = frappe.new_doc("Stock Entry")
+		stock_entry.purpose = "Subcontract"
+		stock_entry.purchase_order = purchase_order.name
+		stock_entry.supplier = purchase_order.supplier
+		stock_entry.supplier_name = purchase_order.supplier_name
+		stock_entry.supplier_address = purchase_order.supplier_address
+		stock_entry.address_display = purchase_order.address_display
+		stock_entry.company = purchase_order.company
+		stock_entry.from_bom = 1
 		for item_code in item_code_list:
-			stock_entry = frappe.new_doc("Stock Entry")
-			stock_entry.purpose = "Subcontract"
-			stock_entry.purchase_order = purchase_order.name
-			stock_entry.supplier = purchase_order.supplier
-			stock_entry.supplier_name = purchase_order.supplier_name
-			stock_entry.supplier_address = purchase_order.supplier_address
-			stock_entry.address_display = purchase_order.address_display
-			stock_entry.company = purchase_order.company
-			stock_entry.docstatus = 0
-			stock_entry.from_bom = 1
 			po_item = [d for d in purchase_order.items if d.item_code == item_code][0]
-			stock_entry.fg_completed_qty = po_item.qty
-			stock_entry.bom_no = po_item.bom
+			bom_no = po_item.bom
 			for rm_item_data in rm_items_list:
 				if rm_item_data["item_code"] == item_code:
 					items_dict = {rm_item_data["rm_item_code"]:
-					{"item_name":rm_item_data["item_name"],
-					"description":item_wh.get(rm_item_data["rm_item_code"]),
-					'qty':rm_item_data["qty"],
-					'from_warehouse':rm_item_data["warehouse"],
-					'stock_uom':rm_item_data["stock_uom"]}}
-					stock_entry.add_to_stock_entry_detail(items_dict)
-			stock_entry.save()
+								{"item_name":rm_item_data["item_name"],
+								"description":item_wh.get(rm_item_data["rm_item_code"]),
+								'qty':rm_item_data["qty"],
+								'from_warehouse':rm_item_data["warehouse"],
+								'stock_uom':rm_item_data["stock_uom"],
+								'bom_no':bom_no}}
+					stock_entry.add_to_stock_entry_detail(items_dict, bom_no)
+		return stock_entry.as_dict()
 	else:
 		frappe.throw(_("No Items selected for transfer"))
 	return purchase_order.name
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index a06645a..81b899a 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -586,9 +586,14 @@
 	if bom.docstatus != 1:
 		if not getattr(frappe.flags, "in_test", False):
 			frappe.throw(_("BOM {0} must be submitted").format(bom_no))
-	if item and not (bom.item.lower() == item.lower() or \
-		bom.item.lower() == cstr(frappe.db.get_value("Item", item, "variant_of")).lower()):
-		frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
+	if item:
+		rm_item_exists = False
+		for d in bom.items:
+			if (d.item_code.lower() == item.lower() or \
+		d.item_code.lower() == cstr(frappe.db.get_value("Item", item, "variant_of")).lower()):
+				rm_item_exists = True
+		if not rm_item_exists:
+			frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
 
 @frappe.whitelist()
 def get_children(doctype, parent=None, is_root=False, **filters):
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 4239751..42ef79b 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -64,13 +64,6 @@
 		self.calculate_rate_and_amount(update_finished_item_rate=False)
 
 	def on_submit(self):
-		if self.purpose == "Subcontract":
-			for d in self.items:
-				if not d.t_warehouse:
-					if self.to_warehouse:
-						d.t_warehouse = self.to_warehouse
-					else:
-						frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
 
 		self.update_stock_ledger()
 
@@ -165,9 +158,7 @@
 				if self.to_warehouse:
 					d.t_warehouse = self.to_warehouse
 				else:
-					#move validation for sub contract to submit
-					if self.purpose != "Subcontract":
-						frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
+					frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
 
 			if self.purpose in ["Manufacture", "Repack"]:
 				if validate_for_manufacture_repack:
@@ -417,7 +408,7 @@
 		"""validation: finished good quantity should be same as manufacturing quantity"""
 		items_with_target_warehouse = []
 		for d in self.get('items'):
-			if d.bom_no and flt(d.transfer_qty) != flt(self.fg_completed_qty) and (d.t_warehouse != getattr(self, "pro_doc", frappe._dict()).scrap_warehouse):
+			if self.purpose != "Subcontract" and d.bom_no and flt(d.transfer_qty) != flt(self.fg_completed_qty) and (d.t_warehouse != getattr(self, "pro_doc", frappe._dict()).scrap_warehouse):
 				frappe.throw(_("Quantity in row {0} ({1}) must be same as manufactured quantity {2}"). \
 					format(d.idx, d.transfer_qty, self.fg_completed_qty))
 
@@ -808,7 +799,7 @@
 	def add_to_stock_entry_detail(self, item_dict, bom_no=None):
 		expense_account, cost_center = frappe.db.get_values("Company", self.company, \
 			["default_expense_account", "cost_center"])[0]
-				
+
 		for d in item_dict:
 			stock_uom = item_dict[d].get("stock_uom") or frappe.db.get_value("Item", d, "stock_uom")