def get_fifo_rate(previous_stock_queue, qty):
 if (qty >= 0):
  total = sum((f[0] for f in previous_stock_queue))
  return ((sum(((flt(f[0]) * flt(f[1])) for f in previous_stock_queue)) / flt(total)) if total else 0.0)
 else:
  (available_qty_for_outgoing, outgoing_cost) = (0, 0)
  qty_to_pop = abs(qty)
  while (qty_to_pop and previous_stock_queue):
   batch = previous_stock_queue[0]
   if (0 < batch[0] <= qty_to_pop):
    available_qty_for_outgoing += flt(batch[0])
    outgoing_cost += (flt(batch[0]) * flt(batch[1]))
    qty_to_pop -= batch[0]
    previous_stock_queue.pop(0)
   else:
    available_qty_for_outgoing += flt(qty_to_pop)
    outgoing_cost += (flt(qty_to_pop) * flt(batch[1]))
    batch[0] -= qty_to_pop
    qty_to_pop = 0
  return (outgoing_cost / available_qty_for_outgoing)

def get_fifo_rate ( previous_stock_queue , qty ) : if ( qty >= 0 ) : total = sum ( ( f [ 0 ] for f in previous_stock_queue ) ) return ( ( sum ( ( ( flt ( f [ 0 ] ) * flt ( f [ 1 ] ) ) for f in previous_stock_queue ) ) / flt ( total ) ) if total else 0.0 ) else : ( available_qty_for_outgoing , outgoing_cost ) = ( 0 , 0 ) qty_to_pop = abs ( qty ) while ( qty_to_pop and previous_stock_queue ) : batch = previous_stock_queue [ 0 ] if ( 0 < batch [ 0 ] <= qty_to_pop ) : available_qty_for_outgoing += flt ( batch [ 0 ] ) outgoing_cost += ( flt ( batch [ 0 ] ) * flt ( batch [ 1 ] ) ) qty_to_pop -= batch [ 0 ] previous_stock_queue . pop ( 0 ) else : available_qty_for_outgoing += flt ( qty_to_pop ) outgoing_cost += ( flt ( qty_to_pop ) * flt ( batch [ 1 ] ) ) batch [ 0 ] -= qty_to_pop qty_to_pop = 0 return ( outgoing_cost / available_qty_for_outgoing )
get fifo rate from queue .