[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
This commit is contained in:
Adrian Torres
2018-11-20 10:51:07 +00:00
parent edfcee0190
commit 407f6e3532
+1
View File
@@ -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.