From 2bcb1b1ca51403448fcc73135e28e497cb24cc99 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 22 Aug 2018 11:51:22 +0200 Subject: [PATCH] [PERF] stock: states 'not it' values changed to 'in' opposite. Purpose: databases with lots of stock moves (3M+) can experience slowness when computing quantities on hand and forecasted. Before this commit, the domains built to compute those quantities from stock_move contained (state not in [done, cancel, draft]). Done and cancel states represent around 95-99% of stock_moves in a normal instance. So selecting all stock_moves then removing done and cancel ones if truly less efficient than taking directly the 'waiting', 'assigned', ... moves especially that the state in indexed in database. After this commit, the domain is build with : (state in [...]) with other state than 'done, 'cancel' and draft. This commit is related to the PR 23030. Thanks to all people that have took part of the conversation and florian-dacosta for the commit --- addons/stock/models/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index c261d25529e..cc5eeb3f3ef 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -120,8 +120,8 @@ class Product(models.Model): Move = self.env['stock.move'] Quant = self.env['stock.quant'] - domain_move_in_todo = [('state', 'not in', ('done', 'cancel', 'draft'))] + domain_move_in - domain_move_out_todo = [('state', 'not in', ('done', 'cancel', 'draft'))] + domain_move_out + domain_move_in_todo = [('state', 'in', ('waiting', 'confirmed', 'assigned', 'partially_available'))] + domain_move_in + domain_move_out_todo = [('state', 'in', ('waiting', 'confirmed', 'assigned', 'partially_available'))] + domain_move_out moves_in_res = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_in_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id')) moves_out_res = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_out_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id')) quants_res = dict((item['product_id'][0], item['quantity']) for item in Quant.read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id'))