Commit d53e053d authored by Titouan Soulard's avatar Titouan Soulard

erp5_core: fix FIFO stock value calculation on null total price

When creating two simulation movements: one adding items in a stock for a
non-zero price, and another adding items in the same stock for a zero price,
the second movement is recorded in the `stock` SQL table with a NULL
`total_price`. This creates issues when computing stock value using the FIFO
method: the total stock value would show as zero in the case described above.

This behaviour is due to operations on NULLs in SQL propagating the NULL value
(eg. 1 + NULL = NULL), which is not what is expected when computing stocks.
This commit treats all NULL prices as zeroes when requesting a stock value
using the FIFO method, which fixes calculation in a right way.
parent e41890f7
Pipeline #35798 canceled with stage
in 0 seconds
......@@ -128,7 +128,7 @@ SELECT
GREATEST(0, quantity-@unbalanced_output)
) AS running_quantity,
(@running_total_asset_price:=@running_total_asset_price +
GREATEST(0, (quantity-@unbalanced_output) * total_price/quantity)
GREATEST(0, (quantity-@unbalanced_output) * IFNULL(total_price,0)/quantity)
) AS running_total_asset_price,
(@unbalanced_output:=GREATEST(0, @unbalanced_output-quantity)) as dummy,
<dtml-if "lowest_value_test">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment