minor improvements
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 42dd409..62f5b88 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -604,27 +604,39 @@
 		from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict
 
 		# item dict = { item_code: {qty, description, stock_uom} }
-		item_dict = get_bom_items_as_dict(self.bom_no, self.company, qty=qty, fetch_exploded = self.use_multi_level_bom)
+		item_dict = get_bom_items_as_dict(self.bom_no, self.company, qty=qty, 
+			fetch_exploded = self.use_multi_level_bom)
 
 		for item in item_dict.values():
 			item.from_warehouse = self.from_warehouse or item.default_warehouse
 		return item_dict
 		
 	def get_transfered_raw_materials(self):
-		raw_materials = frappe.db.sql("""select item_name, item_code, sum(qty) as qty, sed.t_warehouse as warehouse, 
-			description, stock_uom, expense_account, cost_center from `tabStock Entry` se,`tabStock Entry Detail` sed 
-			where se.name = sed.parent and se.docstatus=1 and se.purpose='Material Transfer for Manufacture' and 
-			se.production_order= %s and ifnull(sed.t_warehouse, '') != '' group by sed.item_code, sed.t_warehouse""", 
-			self.production_order, as_dict=1)
+		transferred_materials = frappe.db.sql("""
+			select 
+				item_name, item_code, sum(qty) as qty, sed.t_warehouse as warehouse, 
+				description, stock_uom, expense_account, cost_center 
+			from `tabStock Entry` se,`tabStock Entry Detail` sed 
+			where 
+				se.name = sed.parent and se.docstatus=1 and se.purpose='Material Transfer for Manufacture' 
+				and se.production_order= %s and ifnull(sed.t_warehouse, '') != '' 
+			group by sed.item_code, sed.t_warehouse
+		""", self.production_order, as_dict=1)
 		
-		transfered_materials = frappe.db.sql("""select item_code, sed.s_warehouse as warehouse, sum(qty) as qty from `tabStock Entry` se,
-			`tabStock Entry Detail` sed where se.name = sed.parent and se.docstatus=1 and 
-			se.purpose='Manufacture' and se.production_order= %s and ifnull(sed.s_warehouse, '') != '' 
-			group by sed.item_code, sed.s_warehouse""", self.production_order, as_dict=1)
+		materials_already_backflushed = frappe.db.sql("""
+			select 
+				item_code, sed.s_warehouse as warehouse, sum(qty) as qty 
+			from 
+				`tabStock Entry` se, `tabStock Entry Detail` sed 
+			where 
+				se.name = sed.parent and se.docstatus=1 and se.purpose='Manufacture' 
+				and se.production_order= %s and ifnull(sed.s_warehouse, '') != '' 
+			group by sed.item_code, sed.s_warehouse
+		""", self.production_order, as_dict=1)
 		
-		transfered_qty= {}
-		for d in transfered_materials:
-			transfered_qty.setdefault(d.item_code,[]).append({d.warehouse: d.qty})
+		backflushed_materials= {}
+		for d in materials_already_backflushed:
+			backflushed_materials.setdefault(d.item_code,[]).append({d.warehouse: d.qty})
 		
 		po_qty = frappe.db.sql("""select qty, produced_qty, material_transferred_for_manufacturing from
 			`tabProduction Order` where name=%s""", self.production_order, as_dict=1)[0]
@@ -632,14 +644,14 @@
 		produced_qty = flt(po_qty.produced_qty)
 		trans_qty = flt(po_qty.material_transferred_for_manufacturing)
 		
-		for item in raw_materials:
+		for item in transferred_materials:
 			qty= item.qty
 			
 			if manufacturing_qty > (produced_qty + flt(self.fg_completed_qty)):
 				qty = (qty/trans_qty) * flt(self.fg_completed_qty)
 			
-			elif transfered_qty.get(item.item_code):
-				for d in transfered_qty.get(item.item_code):
+			elif backflushed_materials.get(item.item_code):
+				for d in backflushed_materials.get(item.item_code):
 					if d.get(item.warehouse):
 						qty-= d.get(item.warehouse)