Merge branch 'stock_reco' of github.com:webnotes/erpnext into stock_reco

This commit is contained in:
Anand Doshi 2013-01-14 13:20:30 +05:30
commit e868db33ab
2 changed files with 32 additions and 26 deletions

View File

@ -36,7 +36,8 @@ class TestStockReconciliation(unittest.TestCase):
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 @@ class TestStockReconciliation(unittest.TestCase):
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 @@ class TestStockReconciliation(unittest.TestCase):
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()

View File

@ -56,13 +56,13 @@ def update_entries_after(args, verbose=1):
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 @@ def update_entries_after(args, verbose=1):
(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 @@ def get_serialized_values(qty_after_transaction, sle, valuation_rate):
# 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 @@ def get_moving_average_values(qty_after_transaction, sle, valuation_rate):
# 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 @@ def get_fifo_values(qty_after_transaction, sle, stock_queue):
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)