Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an edge case, where if you have transactions like these then canceling the middle transaction results in double processing of future quantity.
The incorrect data resolves itself in some time once the backdated entry is processed.
This is because:
update_entries_after
Here all SLE that match posting date time (after removing milliseconds) are processed.
erpnext/erpnext/stock/stock_ledger.py
Lines 440 to 461 in c4d20ce
erpnext/erpnext/stock/stock_ledger.py
Lines 1301 to 1314 in c4d20ce
Since step 1 updates all current posting time SLEs, only strictly newer SLEs should be updated while updating qty.
Both these function calls in this order (i.e. this exact code execution path) ONLY occurs when you are making backdated entry.
TODO:
erpnext/erpnext/stock/stock_ledger.py
Lines 1377 to 1385 in c4d20ce
Unrelated fix:
Sort SLEs while picking the next stock reco entry:
0fb6062#diff-7a6f48ad1157b2728d67c44c2bdb26439c7eec44a4241b915070f63fef695f95R1382