[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
This commit is contained in:
Simon Lejeune
2018-01-05 18:28:32 +01:00
parent d4982394bc
commit 25943696ea
+6 -4
View File
@@ -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