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) --HG-- branch : 8.0
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user