Fixed Max value for update FG Item in Production Order
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js
index 657756d..04fcaa5 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order.js
@@ -162,7 +162,7 @@
 	make_se: function(purpose) {
 		var me = this;
 		var max = (purpose === "Manufacture") ?
-			flt(this.frm.doc.qty) - flt(this.frm.doc.produced_qty) :
+			flt(this.frm.doc.material_transferred_for_manufacturing) - flt(this.frm.doc.produced_qty) :
 			flt(this.frm.doc.qty) - flt(this.frm.doc.material_transferred_for_manufacturing);
 
 		frappe.prompt({fieldtype:"Int", label: __("Qty for {0}", [purpose]), fieldname:"qty",
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 65f9ef0..c49129d 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -611,16 +611,16 @@
 		return item_dict
 		
 	def get_transfered_raw_materials(self):
-		items_dict = frappe.db.sql("""select item_name, item_code, sum(qty) as qty, to_warehouse, from_warehouse,
-			description, stock_uom, expense_account, cost_center from `tabStock Entry` se,`tabStock Entry Detail` sed 
+		items_dict = frappe.db.sql("""select item_name, item_code, sum(qty) as qty, sed.s_warehouse as s_warehouse, sed.t_warehouse 
+			as t_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 se.to_warehouse= %s group by sed.item_code""", 
-			(self.production_order, self.from_warehouse), as_dict=1)
+			se.production_order= %s and ifnull(sed.s_warehouse, '') != '' group by sed.item_code, sed.s_warehouse, sed.t_warehouse""", 
+			self.production_order, as_dict=1)
 		
 		transfered_materials = frappe.db.sql("""select item_code, 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 se.from_warehouse= %s 
-			group by sed.item_code""", (self.production_order, self.from_warehouse), as_dict=1)
+			se.purpose='Manufacture' and se.production_order= %s and ifnull(sed.s_warehouse, '') != '' 
+			group by sed.item_code, sed.s_warehouse, sed.t_warehouse""", self.production_order, as_dict=1)
 		
 		transfered_qty= {}
 		for d in transfered_materials:
@@ -644,8 +644,8 @@
 			if qty > 0:
 				self.add_to_stock_entry_detail({
 					item.item_code: {
-						"to_warehouse": item.to_warehouse,
-						"from_warehouse": item.from_warehouse,
+						"to_warehouse": item.t_warehouse,
+						"from_warehouse": item.s_warehouse,
 						"qty": qty,
 						"item_name": item.item_name,
 						"description": item.description,