From 64d7c4b2d56db4698ab1dd590f755a7e6bb0b215 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 17 Jan 2013 12:22:59 +0530 Subject: [PATCH] fixes in get_incoming_rate --- stock/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stock/utils.py b/stock/utils.py index e7702a89fd..46dd9d01a9 100644 --- a/stock/utils.py +++ b/stock/utils.py @@ -111,7 +111,7 @@ def get_fifo_rate(previous_stock_queue, qty): else: outgoing_cost = 0 qty_to_pop = abs(qty) - while qty_to_pop: + while qty_to_pop and previous_stock_queue: batch = previous_stock_queue[0] if 0 < batch[0] <= qty_to_pop: # if batch qty > 0 @@ -124,8 +124,8 @@ def get_fifo_rate(previous_stock_queue, qty): outgoing_cost += flt(qty_to_pop) * flt(batch[1]) batch[0] -= qty_to_pop qty_to_pop = 0 - - return outgoing_cost / abs(qty) + # if queue gets blank and qty_to_pop remaining, get average rate of full queue + return outgoing_cost / abs(qty) - qty_to_pop def get_valid_serial_nos(sr_nos, qty=0, item_code=''): """split serial nos, validate and return list of valid serial nos"""