testcase for stock reco
diff --git a/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/stock/doctype/stock_reconciliation/test_stock_reconciliation.py
index 224d70e..fb85f65 100644
--- a/stock/doctype/stock_reconciliation/test_stock_reconciliation.py
+++ b/stock/doctype/stock_reconciliation/test_stock_reconciliation.py
@@ -36,7 +36,8 @@
 		webnotes.conn.rollback()
 		
 	def test_reco_for_fifo(self):
-		# [[qty, valuation_rate, posting_date, posting_time, expected_stock_value, bin_qty]]
+		# [[qty, valuation_rate, posting_date, 
+		#		posting_time, expected_stock_value, bin_qty, bin_valuation]]
 		input_data = [
 			[50, 1000, "2012-12-26", "12:00", 50000, 45, 48000], 
 			[5, 1000, "2012-12-26", "12:00", 5000, 0, 0], 
@@ -73,20 +74,21 @@
 			self.setUp()
 					
 		
-	def atest_reco_for_moving_average(self):
-		# [[qty, valuation_rate, posting_date, posting_time]]
+	def test_reco_for_moving_average(self):
+		# [[qty, valuation_rate, posting_date, 
+		#		posting_time, expected_stock_value, bin_qty, bin_valuation]]
 		input_data = [
-			[50, 1000, "2012-12-26", "12:00", 50000], 
-			[5, 1000, "2012-12-26", "12:00", 5000], 
-			[15, 1000, "2012-12-26", "12:00", 15000], 
-			[25, 900, "2012-12-26", "12:00", 22500], 
-			[20, 500, "2012-12-26", "12:00", 10000], 
-			[50, 1000, "2013-01-01", "12:00", 50000], 
-			[5, 1000, "2013-01-01", "12:00", 5000],
-			["", 1000, "2012-12-26", "12:05", 15000],
-			[20, "", "2012-12-26", "12:05", 18000],
-			[10, 2000, "2012-12-26", "12:10", 20000],
-			[1, 1000, "2012-12-01", "00:00", 1000],
+			[50, 1000, "2012-12-26", "12:00", 50000, 45, 48000], 
+			[5, 1000, "2012-12-26", "12:00", 5000, 0, 0], 
+			[15, 1000, "2012-12-26", "12:00", 15000, 10, 12000], 
+			[25, 900, "2012-12-26", "12:00", 22500, 20, 22500], 
+			[20, 500, "2012-12-26", "12:00", 10000, 15, 18000], 
+			[50, 1000, "2013-01-01", "12:00", 50000, 65, 68000], 
+			[5, 1000, "2013-01-01", "12:00", 5000, 20, 23000],
+			["", 1000, "2012-12-26", "12:05", 15000, 10, 12000],
+			[20, "", "2012-12-26", "12:05", 18000, 15, 18000],
+			[10, 2000, "2012-12-26", "12:10", 20000, 5, 6000],
+			[1, 1000, "2012-12-01", "00:00", 1000, 11, 13200],
 		]
 		
 		for d in input_data:
@@ -101,6 +103,12 @@
 				
 			self.assertEqual(res and flt(res[0][0], 4) or 0, d[4])
 			
+			bin = webnotes.conn.sql("""select actual_qty, stock_value from `tabBin`
+				where item_code = 'Android Jack D' and warehouse = 'Default Warehouse'""")
+			
+			self.assertEqual(bin and [flt(bin[0][0]), flt(bin[0][1], 4)] or [], 
+				[flt(d[5]), flt(d[6])])
+						
 			self.tearDown()
 			self.setUp()
 			
diff --git a/stock/stock_ledger.py b/stock/stock_ledger.py
index 3cad355..7d19c9c 100644
--- a/stock/stock_ledger.py
+++ b/stock/stock_ledger.py
@@ -56,13 +56,13 @@
 				continue
 
 		if sle.serial_no:
-			valuation_rate, incoming_rate = get_serialized_values(qty_after_transaction, sle,
+			valuation_rate = get_serialized_values(qty_after_transaction, sle,
 				valuation_rate)
 		elif valuation_method == "Moving Average":
-			valuation_rate, incoming_rate = get_moving_average_values(qty_after_transaction, sle,
+			valuation_rate = get_moving_average_values(qty_after_transaction, sle,
 				valuation_rate)
 		else:
-			valuation_rate, incoming_rate = get_fifo_values(qty_after_transaction, sle,
+			valuation_rate = get_fifo_values(qty_after_transaction, sle,
 				stock_queue)
 				
 		qty_after_transaction += flt(sle.actual_qty)
@@ -75,15 +75,13 @@
 				(qty_after_transaction * valuation_rate) or 0
 		else:
 			stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in stock_queue))
-			
-		# print sle.posting_date, qty_after_transaction, incoming_rate, valuation_rate
-			
+						
 		# update current sle
 		webnotes.conn.sql("""update `tabStock Ledger Entry`
 			set qty_after_transaction=%s, valuation_rate=%s, stock_queue=%s,
-			stock_value=%s, incoming_rate = %s where name=%s""", 
+			stock_value=%s where name=%s""", 
 			(qty_after_transaction, valuation_rate,
-			json.dumps(stock_queue), stock_value, incoming_rate, sle.name))
+			json.dumps(stock_queue), stock_value, sle.name))
 	
 	if _exceptions:
 		_raise_exceptions(args, verbose)
@@ -188,11 +186,11 @@
 				# else it remains the same as that of previous entry
 				valuation_rate = new_stock_value / new_stock_qty
 				
-	return valuation_rate, incoming_rate
+	return valuation_rate
 	
 def get_moving_average_values(qty_after_transaction, sle, valuation_rate):
 	incoming_rate = flt(sle.incoming_rate)
-	actual_qty = flt(sle.actual_qty)
+	actual_qty = flt(sle.actual_qty)	
 	
 	if not incoming_rate:
 		# In case of delivery/stock issue in_rate = 0 or wrong incoming rate
@@ -212,7 +210,7 @@
 	
 	# NOTE: val_rate is same as previous entry if new stock value is negative
 	
-	return valuation_rate, incoming_rate
+	return valuation_rate
 	
 def get_fifo_values(qty_after_transaction, sle, stock_queue):
 	incoming_rate = flt(sle.incoming_rate)
@@ -255,7 +253,7 @@
 
 	valuation_rate = stock_qty and (stock_value / flt(stock_qty)) or 0
 
-	return valuation_rate, incoming_rate
+	return valuation_rate
 
 def _raise_exceptions(args, verbose=1):
 	deficiency = min(e["diff"] for e in _exceptions)