From 407f6e35321eeeadeb8f56207475bf77d13b2fc7 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Fri, 16 Nov 2018 10:16:54 +0000 Subject: [PATCH] [FIX] stock: do not prefetch stock.move fields For a SO of 300 lines, when confirmed, it takes 195s to process stock moves for the SO, which is an insane amount of time for any kind of process in Odoo. This happens because stock.move is a heavy model with lots of fields, prefetching all these fields at once can hinder performance when processing a lot of stock.moves. To reduce the processing time, the prefetching is disabled in the specific scenario of processing stock moves and pickings on SO confirmation. This patch increases the performance of SO validation (with stock installed) by ~30%. Pre-patch: 195s (300 SOL) Post-patch: 135s (300 SOL) closes odoo/odoo#28835 --- addons/stock/models/stock_move.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 0e3c8fa6d81..21469aeed00 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -578,6 +578,7 @@ class StockMove(models.Model): moves_to_merge = [] for candidate_moves in candidate_moves_list: # First step find move to merge. + candidate_moves = candidate_moves.with_context(prefetch_fields=False) for k, g in groupby(sorted(candidate_moves, key=self._prepare_merge_move_sort_method), key=itemgetter(*distinct_fields)): moves = self.env['stock.move'].concat(*g).filtered(lambda m: m.state not in ('done', 'cancel', 'draft')) # If we have multiple records we will merge then in a single one.