Inconsistency in Stock Ledger

I have noticed some Inconsistency in Stock Ledger. This inconsistency is leading to wrong Balance Qty in ERPNext.

Please refer to the below screenshot

The cell highlighted should have a Balance Qty of 13, since this item has only been decreased by 1 Qty since last transaction when the Balance was 14. For some reason, the Balance Qty is 0.
These transactions are not back-dated therefore it is unlikely that this issue is arising out of Repost Item Valuation.

I checked the corresponding Stock Ledger Entry, here is the snapshot

Has anyone faced a similar issue? Not sure how to reproduce this issue either.

Note: The item is a serialised Item

By any chance was Negative stock enabled?

Nope, Negative Stock was never enabled

My findings so far

The Actual Qty after Transaction field in Stock Ledger entry for Previous Stock Ledger Entry (for Item and Warehouse combination) is not calculated correctly for some reason, which is leading to wrong Actual Qty after Transaction in current SLE (Current qty_after_transaction = Previous qty_after_transaction + actual_quantity. Not able to find the cause of this issue but looks like this is the problem

I was able to fix the issue (symptomatically) by setting the correct Actual Qty after Transaction at DB level, but still need to find the root cause

Not sure if this report will help in any way

It will be helpful, if someone from Frappe can explain what was the purpose of building this report and if they have faced a similar issue before


I am facing Similar issue with my instance my whole stock is messed up because of this, I am on erpnext version 13.6.0.
I have also enabled negative stock. Is it something which is causing this problem?
Please help with this

@Manan_Shah have you solved your issue? I have discovered the same case when creating a stock reconciliation, a pop-up message appears when trying to submit it. Upon checking the current qty and the current serial no count is not the same. The current active serial number is 506 while 491 stocks are on the stock ledger.

On your case, after seeing the inconsistency of the stock ledger, do you have more serial numbers than the qty on the stock ledger?

Yes we have more serial Nos than the Qty in Stock Balance
This inconsistency is seen in the Stock Ledger, the root cause for this is still unknown

Take a look at “Serial No Status” report and check the status

@Francisco_Buendia do you know can I create another stock ledger entry? I think this case was because of a cancelled delivery note. A cancelled transaction should automatically create a positive stock ledger entry, however, ERPNEXT did not do it.

With this, the stock ledger qty balance is incorrect. Now, I need to create or refresh the stock ledger report so that the qty will be corrected.

Do you know how to do it since I am not a developer/programmer so I have no idea how to do it :frowning:

wait for someone to check on this.

No, sorry, user cannot create Stock Ledger Entry, but try looking if there’s any Repost Item Valuation stucked.

We’re having tha same issue in V13.15.2

I’ve posted an issue in github.
It’d help for you to comment on it ti give it greater priority.

We are still having these inconsistencies in Stock Ledger in the latest versions. Anyone yet figure out a fix?

It will keep happening when stock is removed from same warehouse at same time by multiple users/browser tabs.

I have been trying to fight this problem for a very long time, not that I have managed to successfully fix it but I do notice this happening if the system is very busy i.e. there are alot of users and alot of stock related transactions.

I actually think it may have something to do with DB calls, rollbacks and commits etc. Been studying this for a long time now but still cannot conclude why exactly this happens.

Is there any chance someone who is seriously knowledgable about the Stock Ledger Entries can assist with this? perhaps from the Frappe team. It is from my POV quite a serious problem.