Error with Bin Calculations


I set up an Item as a Batched Item. I then made a Purchase Receipt of his item with two batches BAT1 and BAT2 each for 10 Nos.

Then I made a Delivery Note for BAT1 for 5 Nos.

In between the times of these two transactions, I revised the quantity of BAT2 to 5 using Stock Reconciliation. So the Actual Quantity in the Bin for this item should show: 10+10-5-5 = 10, right. But ERPNext ver 13.40.2 (version-13) and Frappe ver 13.41.7 (version-13) is showing actual quantity in the Bin Doc as -25.

Not sure if this occurs only for batched items. Or only for Stock Reconciliation transactions, or the combination of batched items being corrected using stock reconciliation, but can somebody that knows coding please check this code segment and see if you can figure out where the problem is?

As the Actual Quantity in the Bin Doc is showing as -25, I cannot make any outward transactions even though the Stock Balance Report and the Batch-Wise Balance History are showing the correct numbers. (5 of BAT1 and 5 of BAT2).

The other thing I noticed was that the impact of the Stock Reconciliation on the Stock Ledger was -10 of BAT2 and +5 of BAT2. Which works fine if you haven’t made any outward transactions after the date/time of the stock reconciliation (let’s say the stock reconciliation is something you have to do predated or pre-timed). So let’s say you shipped out 2 Nos of BAT2. And you now have to submit a Stock Reconciliation for BAT2 prior to the 2 Nos Outward transaction. How will this be handled? Will the code fail? I think till recently, ERPNext was not permitting Stock Reconciliation of Batched and Serialized item. You’d have to submit a Stock Entry Material Receipt or Issue to correct the quantities. I think that would perhaps have addressed the -10 +5 impact on the Stock Ledger. Again I am not sure if this behavior is for batched items. Again if somebody knowledgeable could take a peek at the code, you may be able to figure out if the logic is appropriate.

There seems to be some validations/controls for outbound transactions in place around Actual Quantity as calculated in the Bin. There does not seem to be a datetime dimension to the Bin record, so I am not really sure if validations/controls for outbound transactions around Actual Quantity as calculated in the Bin is a good idea at all. Is there anyway to turn off this validation? Or make the validation more robust by using the Stock Ledger Entry records (which has a datetime dimension and also does quantity tracking at the batch level)?

And no, I haven’t turned on negative stock.

Thank you for your attention.



On version 13, the trouble seems to be with making Stock Reconciliation for batched items (need to validate this for items that are not batches) that are retrospective effect - like date or time is prior to the current datetime.

But using material issue (or receipt) with a retrospective effect does not seem to be creating any problems. Doing Stock Reconciliation after the last transaction for the item(s) does not seem to be creating any problems.

It’s the specific case where a stock reconciliation for a batched item that is passed with retrospective effect prior to the last chronological stock transaction for an item(s) that seems to completely throw off the Actual Quantity in the Bin Record.

The way I see it, there are two problems:

  1. Fixing the Actual Quantity bug in the code.
  2. This is more important: Validating Actual Quantity in Bin Record for outbound transactions is a major design defect, I think. I think some validation of Actual Quantity in Bin record is being done for outbound transactions. Validating outbound quantities based on Actual Quantity in the Bin Record is a major design defect especially considering that the Bin record does not seem to have a datetime dimension to it.