From 25943696ea00b140ea19de1c6ee6a42d97d8e2f7 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Fri, 5 Jan 2018 16:32:46 +0100 Subject: [PATCH] [FIX] stock: _compute_entire_package_ids When a picking contain a few thousands move line, reading it was slow because of the computation of "entire_package_ids" and "entire_package_detail_ids". The compute method for this field calls "_check_move_lines_map_quant_package" that check that, for a picking, all the move lines having "package_id" and "result_package_id" as the same package (ie moving an entire pack) match exactly the content of the package (ie the quants). The issue was that the method was called for every move line without packaging because of a wrongly written condition. We now only call the method one time for each package, whatever the number of move line. opw-803887 --- addons/stock/models/stock_picking.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 213c54a4c7a..71fd5cb3d69 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -405,10 +405,12 @@ class Picking(models.Model): """ for picking in self: packages = self.env['stock.quant.package'] - for ml in picking.move_line_ids: - if ml.package_id.id == ml.result_package_id.id: - if picking.state in ('done', 'cancel') or picking._check_move_lines_map_quant_package(ml.package_id): - packages |= ml.package_id + packages_to_check = picking.move_line_ids\ + .filtered(lambda ml: ml.result_package_id and ml.package_id.id == ml.result_package_id.id)\ + .mapped('package_id') + for package_to_check in packages_to_check: + if picking.state in ('done', 'cancel') or picking._check_move_lines_map_quant_package(package_to_check): + packages |= package_to_check picking.entire_package_ids = packages picking.entire_package_detail_ids = packages