details: https://code.tryton.org/tryton/commit/632da87e09dd
branch: 8.0
user: Cédric Krier <[email protected]>
date: Thu Sep 24 09:27:50 2026 +0200
description:
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
(grafted from 6267ce266fcf8e9494eb277996e948c9dfe21d1d)
diffstat:
modules/stock/stock_reporting.py | 7 ++-
modules/stock/tests/scenario_stock_reporting_inventory.rst | 28 ++++++++++++++
2 files changed, 32 insertions(+), 3 deletions(-)
diffs (54 lines):
diff -r 6e3febdbd8ed -r 632da87e09dd modules/stock/stock_reporting.py
--- a/modules/stock/stock_reporting.py Wed Sep 23 17:59:29 2026 +0200
+++ b/modules/stock/stock_reporting.py Thu Sep 24 09:27:50 2026 +0200
@@ -583,11 +583,12 @@
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):
diff -r 6e3febdbd8ed -r 632da87e09dd
modules/stock/tests/scenario_stock_reporting_inventory.rst
--- a/modules/stock/tests/scenario_stock_reporting_inventory.rst Wed Sep
23 17:59:29 2026 +0200
+++ b/modules/stock/tests/scenario_stock_reporting_inventory.rst Thu Sep
24 09:27:50 2026 +0200
@@ -244,3 +244,31 @@
>>> 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