Include the minimal input/output quantity the same day as input in the average quantity for the turnover

Such quantity should be accounted as staying 1 day in the warehouse otherwise
we may have more quantity leaving than the average stock.

Closes #15014
This commit is contained in:
Cédric Krier
2026-09-24 09:27:50 +02:00
parent 6fbd38e9d5
commit eebd27fa79
2 changed files with 32 additions and 3 deletions
+4 -3
View File
@@ -583,11 +583,12 @@ class InventoryTurnover(ModelSQL, ModelView):
inventory_from_date = _SQLite_JulianDay(inventory_from_date)
inventory_to_date = _SQLite_JulianDay(inventory_to_date)
average_quantity = (
Sum(Case(
(inventory.quantity >= 0, inventory.quantity),
else_=0)
(Sum(Greatest(inventory.quantity, 0)
* (inventory_to_date - inventory_from_date
+ Case((inventory.to_date == to_date, 1), else_=0)))
+ Sum(Least(
Greatest(inventory.input_quantity, 0),
Greatest(inventory.output_quantity, 0))))
/ days)
def round_sql(expression, digits=2):
@@ -244,3 +244,31 @@ Check Inventory turnover::
>>> turnover.turnover
0.045
>>> assertEqual(turnover.product_reference.__class__.__name__, product_type)
>>> with config.set_context(
... location=warehouse_loc.id,
... from_date=dt.date(2025, 1, 1),
... to_date=dt.date(2025, 1, 1),
... product_type=product_type):
... turnover, = InventoryTurnover.find([])
>>> turnover.output_quantity
1.0
>>> turnover.average_quantity
10.0
>>> turnover.turnover
0.1
>>> with config.set_context(
... location=warehouse_loc.id,
... from_date=dt.date(2025, 1, 1),
... to_date=dt.date(2025, 1, 5),
... product_type=product_type):
... turnover, = InventoryTurnover.find([])
>>> turnover.output_quantity
0.2
>>> turnover.average_quantity
9.2
>>> turnover.turnover
0.022