From 4730ef7b9b3aad865ebaedb6758c7b25dc8477d3 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Thu, 18 Feb 2021 11:28:52 +0100 Subject: [PATCH] fix(stock): add WHERE to max values Adds a missing WHERE to the max values to appropriately compute the max_values table calculation. Seems to also speed up the computation greatly. --- server/models/procedures/stock.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/server/models/procedures/stock.sql b/server/models/procedures/stock.sql index 07e57e017e..d8d6ddc013 100644 --- a/server/models/procedures/stock.sql +++ b/server/models/procedures/stock.sql @@ -436,6 +436,7 @@ CREATE PROCEDURE ComputeStockStatusForStagedInventory( SELECT sms.inventory_uuid, tmd.max_date, sms.sum_quantity, sms.sum_in_quantity, sms.sum_out_quantity_exit, sum_out_quantity_consumption FROM stock_movement_status AS sms JOIN tmp_max_dates AS tmd ON sms.inventory_uuid = tmd.inventory_uuid AND tmd.max_date = sms.date + WHERE sms.depot_uuid = _depot_uuid GROUP BY sms.inventory_uuid, sms.date; -- we don't need to know those max dates anymore