[FIX] stock_account: handle neg. quant valuation #165179
Open
+75
−2
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.
Current behavior:
Switching from manual to automated valuation on a product that has a negative quantity will create entries in the valuation journal with incorrect debit/credit figures.
Expected behavior:
The lines generated in this manner should look like ones created when the valuation is generated for a product that was already valuated with the automated option.
Steps to reproduce:
Create a product category with the default manual valuation method, create a storable product that belongs to it
Sell some quantity of the new product without adding any on-hand quantity (so that the qty is negative), confirm the order and generate the invoice
Swap to automated valuation in the product category that was created in step 1
In the entries for the stock valuation journal, observe that:
A) the stock valuation account is getting debited instead of credited, and
B) the other entry generated is for the stock input account
instead of stock output, and
C) the debit/credit amounts should be swapped here as well
Cause of the issue:
The negative quantity case is not considered when we do the empty/replenish sequence on valuation method change.
Fix:
Add an explicit check for negative quantity in the replenish step of changing valuation method.
opw-3810779