Merge pull request #992 from akhileshdarjee/master

[fix] production order transfer raw material to fetch all necessary data
diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js
index 7301bd5..b471256 100644
--- a/stock/doctype/stock_entry/stock_entry.js
+++ b/stock/doctype/stock_entry/stock_entry.js
@@ -144,11 +144,18 @@
 	},
 	
 	production_order: function() {
+		var me = this;
 		this.toggle_enable_bom();
 		
 		return this.frm.call({
 			method: "get_production_order_details",
-			args: {production_order: this.frm.doc.production_order}
+			args: {production_order: this.frm.doc.production_order},
+			callback: function(r) {
+				if (!r.exc) {
+					if (me.frm.doc.purpose == "Material Transfer" && !me.frm.doc.to_warehouse)
+						me.frm.set_value("to_warehouse", r.message["wip_warehouse"]);
+				}
+			}
 		});
 	},
 	
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index e4fa9d9..7ec2ba3 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -472,11 +472,12 @@
 				if self.doc.purpose=="Material Receipt":
 					self.doc.from_warehouse = ""
 					
-				item = webnotes.conn.sql("""select item, description, uom from `tabBOM`
-					where name=%s""", (self.doc.bom_no,), as_dict=1)
+				item = webnotes.conn.sql("""select name, item_name, description, uom 
+					from `tabItem` where name=%s""", (self.doc.bom_no), as_dict=1)
 				self.add_to_stock_entry_detail({
 					item[0]["item"] : {
 						"qty": self.doc.fg_completed_qty,
+						"item_name": item[0].item_name,
 						"description": item[0]["description"],
 						"stock_uom": item[0]["uom"],
 						"from_warehouse": ""
@@ -484,7 +485,6 @@
 				}, bom_no=self.doc.bom_no)
 		
 		self.get_stock_and_rate()
-		
 	
 	def get_bom_raw_materials(self, qty):
 		""" 
@@ -503,9 +503,12 @@
 				else:
 					item_dict[item.item_code] = {
 						"qty": flt(item.qty), 
+						"item_name": item.item_name, 
 						"description": item.description, 
 						"stock_uom": item.stock_uom,
-						"from_warehouse": item.default_warehouse
+						"from_warehouse": item.default_warehouse,
+						"expense_account": item.purchase_account,
+						"cost_center": item.cost_center
 					}
 		
 		if self.doc.use_multi_level_bom:
@@ -515,7 +518,10 @@
 					ifnull(sum(fb.qty_consumed_per_unit),0)*%s as qty, 
 					fb.description, 
 					fb.stock_uom,
-					it.default_warehouse
+					it.item_name,
+					it.default_warehouse,
+					it.purchase_account,
+					it.cost_center
 				from 
 					`tabBOM Explosion Item` fb,`tabItem` it 
 				where 
@@ -532,10 +538,13 @@
 			# get only BOM items
 			fl_bom_sa_items = sql("""select 
 					`tabItem`.item_code,
+					`tabItem`.item_name,
 					ifnull(sum(`tabBOM Item`.qty_consumed_per_unit), 0) *%s as qty,
 					`tabItem`.description, 
 					`tabItem`.stock_uom,
-					`tabItem`.default_warehouse
+					`tabItem`.default_warehouse,
+					`tabItem`.purchase_account,
+					`tabItem`.cost_center
 				from 
 					`tabBOM Item`, `tabItem`
 				where 
@@ -599,16 +608,24 @@
 		return issued_item_qty
 
 	def add_to_stock_entry_detail(self, item_dict, bom_no=None):
+		idx = 1
+		expense_account, cost_center = webnotes.conn.get_values("Company", self.doc.company, \
+			["default_expense_account", "cost_center"])[0]
+
 		for d in item_dict:
 			se_child = addchild(self.doc, 'mtn_details', 'Stock Entry Detail', 
 				self.doclist)
+			se_child.idx = idx
 			se_child.s_warehouse = item_dict[d].get("from_warehouse", self.doc.from_warehouse)
 			se_child.t_warehouse = item_dict[d].get("to_warehouse", self.doc.to_warehouse)
 			se_child.item_code = cstr(d)
+			se_child.item_name = item_dict[d]["item_name"]
 			se_child.description = item_dict[d]["description"]
 			se_child.uom = item_dict[d]["stock_uom"]
 			se_child.stock_uom = item_dict[d]["stock_uom"]
 			se_child.qty = flt(item_dict[d]["qty"])
+			se_child.expense_account = item_dict[d]["expense_account"] or expense_account
+			se_child.cost_center = item_dict[d]["cost_center"] or cost_center
 			
 			# in stock uom
 			se_child.transfer_qty = flt(item_dict[d]["qty"])
@@ -617,6 +634,9 @@
 			# to be assigned for finished item
 			se_child.bom_no = bom_no
 
+			# increment idx by 1
+			idx += 1
+
 	def get_cust_values(self):
 		"""fetches customer details"""
 		if self.doc.delivery_note_no:
@@ -682,8 +702,8 @@
 @webnotes.whitelist()
 def get_production_order_details(production_order):
 	result = webnotes.conn.sql("""select bom_no, 
-		ifnull(qty, 0) - ifnull(produced_qty, 0) as fg_completed_qty, use_multi_level_bom
-		from `tabProduction Order` where name = %s""", production_order, as_dict=1)
+		ifnull(qty, 0) - ifnull(produced_qty, 0) as fg_completed_qty, use_multi_level_bom, 
+		wip_warehouse from `tabProduction Order` where name = %s""", production_order, as_dict=1)
 	return result and result[0] or {}
 	
 def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
diff --git a/stock/doctype/stock_entry_detail/stock_entry_detail.txt b/stock/doctype/stock_entry_detail/stock_entry_detail.txt
index b766250..5218c1a 100644
--- a/stock/doctype/stock_entry_detail/stock_entry_detail.txt
+++ b/stock/doctype/stock_entry_detail/stock_entry_detail.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-03-29 18:22:12", 
   "docstatus": 0, 
-  "modified": "2013-10-15 14:58:09", 
+  "modified": "2013-10-23 14:35:46", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -67,6 +67,14 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "item_name", 
+  "fieldtype": "Data", 
+  "label": "Item Name", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "description", 
   "fieldtype": "Text", 
   "in_list_view": 1, 
diff --git a/stock/page/stock_home/stock_home.js b/stock/page/stock_home/stock_home.js
index 713fe28..ecfc6fe 100644
--- a/stock/page/stock_home/stock_home.js
+++ b/stock/page/stock_home/stock_home.js
@@ -81,7 +81,7 @@
 			},
 			{
 				"doctype":"Item Price",
-				"label": wn._("Price List"),
+				"label": wn._("Item Price"),
 				"description": wn._("Multiple Item prices.")
 			},
 			{