[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
This commit is contained in:
Florian da Costa
2018-08-22 11:53:56 +02:00
committed by William Henrotin
parent f201e720c4
commit 2bcb1b1ca5
+2 -2
View File
@@ -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'))