Some minor fixes
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 865514b..c4ba9e7 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -223,7 +223,8 @@
 				})
 				if not rm.rate:
 					from erpnext.stock.stock_ledger import get_valuation_rate
-					rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse)
+					rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse, 
+						self.doctype, self.name)
 			else:
 				rm.rate = bom_item.rate
 
diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json
index c05c5f3..aad8ed0 100644
--- a/erpnext/stock/doctype/item/test_records.json
+++ b/erpnext/stock/doctype/item/test_records.json
@@ -15,6 +15,7 @@
   "item_group": "_Test Item Group",
   "item_name": "_Test Item",
   "apply_warehouse_wise_reorder_level": 1,
+  "valuation_rate": 100,
   "reorder_levels": [
    {
     "material_request_type": "Purchase",
@@ -61,6 +62,7 @@
   "item_code": "_Test Item Home Desktop 100",
   "item_group": "_Test Item Group Desktops",
   "item_name": "_Test Item Home Desktop 100",
+  "valuation_rate": 100,
   "taxes": [
    {
     "doctype": "Item Tax",
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index ef48b3a..a4cc512 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -260,7 +260,8 @@
 				self.valuation_rate = sle.incoming_rate
 		
 		if not self.valuation_rate:
-			self.valuation_rate = get_valuation_rate(sle, self.allow_zero_rate)
+			self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, 
+				sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
 
 	def get_fifo_values(self, sle):
 		incoming_rate = flt(sle.incoming_rate)
@@ -285,7 +286,8 @@
 			while qty_to_pop:
 				if not self.stock_queue:
 					# Get valuation rate from last sle if exists or from valuation rate field in item master
-					_rate = get_valuation_rate(sle, self.allow_zero_rate)
+					_rate = get_valuation_rate(sle.item_code, sle.warehouse, 
+				sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
 					self.stock_queue.append([0, _rate])
 
 				index = None
@@ -405,32 +407,32 @@
 			"order": order
 		}, previous_sle, as_dict=1, debug=debug)
 
-def get_valuation_rate(sle, allow_zero_rate=False):
+def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, allow_zero_rate=False):
 	# Get valuation rate from last sle for the same item and warehouse
 	last_valuation_rate = frappe.db.sql("""select valuation_rate
 		from `tabStock Ledger Entry`
 		where item_code = %s and warehouse = %s
 		and valuation_rate > 0
-		order by posting_date desc, posting_time desc, name desc limit 1""", (sle.item_code, sle.warehouse))
+		order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse))
 
 	if not last_valuation_rate:
 		# Get valuation rate from last sle for the item against any warehouse
 		last_valuation_rate = frappe.db.sql("""select valuation_rate
 			from `tabStock Ledger Entry`
 			where item_code = %s and valuation_rate > 0
-			order by posting_date desc, posting_time desc, name desc limit 1""", sle.item_code)
+			order by posting_date desc, posting_time desc, name desc limit 1""", item_code)
 
 	valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0
 
 	if not valuation_rate:
 		# If negative stock allowed, and item delivered without any incoming entry,
 		# syste does not found any SLE, then take valuation rate from Item
-		valuation_rate = frappe.db.get_value("Item", sle.item_code, "valuation_rate")
+		valuation_rate = frappe.db.get_value("Item", item_code, "valuation_rate")
 
 	if not allow_zero_rate and not valuation_rate \
 			and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
 			
 		frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries (for booking expenses). Please create an incoming stock transaction or mention valuation rate in Item record, and then try submiting {1} {2}")
-		.format(sle.item_code, sle.voucher_type, sle.voucher_no))
+		.format(item_code, voucher_type, voucher_no))
 
 	return valuation_rate