I think this is ‘Urgent Issue’ that’s needs to be fixed as many ERPNext users including me are using it for production use. I just aware and I can say my stock value is wrong now due to this issue.
Repack Entry for batch items doesn’t look-up FIFO rate. (both source and target are batch items)
Steps to reproduce issue:
Make 3 purchase receipts for 1 item with different qty and rate.
Make repack, take 3rd batch id as source then create another batch-item. Set this new item as target
Upon save, the value is calculated from 1st batch value, not from 3rd batch value. Fifo in-out should look-up the value per batch-id value if it is batch item
@nabinhait …Is this the code to get fifo rate (under ~/stock/utils.py) on submitting delivery note, sales invoice? Why it still doesn’t consider Batch ID on posting Cost of Goods Sold?
Can you help pointing out so that the FIFO system shall look-up Batch-ID/Serial No on posting Accounting entries?
def get_fifo_rate(previous_stock_queue, qty):
"""get FIFO (average) Rate from Queue"""
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:
# if batch qty > 0
# not enough or exactly same qty in current batch, clear batch
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:
# all from current batch
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
The fix is not very easy. You have to maintain FIFO stack, like [[qty1, batch1, rate1], [qty2, batch2, rate2]] and while delivering you have to pick up qty and rate based on FIFO considering batch. Also we have to rebuild fifo stack for existing stock ledger entries.
This is an issue I’m running into as well. Specifically, I’d like Material Transfer for Manufacture to autopopulate batches based on FIFO. Please let me know if there’s been any progress, of it the issue has been raised on Github.
Austin
Im not sure if anyone else is working in this but im planning to add an addittion costing model called “lot cost” which will provide costs based on receipted lots. Our current erp system works this way. I dont just want to hardcode this as many are using the other methods of valuation, and I can do it if I want in my fork but would like to contribute back
Also when it comes to stock valuation it’s not a good idea to mix methods so also have to consider this and how to switch between methods for current stock movements.
It’s challenging trying to understand the current code base for me and taking time as my other responsibilities at work is taking priority.
In principal all I’m planning to do is store all stock receipts with an auto generated lot number and the users will pick this lot number for the other stock movement docs. All stock costs lookups will use this lot number for valuation. If multiple lots are picked during a single movement then the cost is the sum of the lot costs.
Im sure there will be challenges with this in some business use cases but this is my initial design plan. Just trying to figure out how and where to make appropriate changes that is really configurable.