[FIX] stock: improve perf of _compute_has_packages of stock.picking

When a picking contains a lot (> 10000) of stock move line, the time
to open the picking become a issue (for 50000 sml, +- 6.5 sec) because of the
`_compute_has_packages`. Use a search with a limit=1 to avoid fetching
all `stock.move.line` with `result_package_id`
(for 50000 sml, +- 2.5 sec).

opw-2371161

X-original-commit: e78ca55997dfbf13c0798c1f59408450071e1452
This commit is contained in:
Rémy Voet (ryv)
2020-12-07 07:49:13 +00:00
parent bc915be77f
commit 8f2c4ef9ca
+1 -1
View File
@@ -527,7 +527,7 @@ class Picking(models.Model):
def _compute_has_packages(self):
for picking in self:
picking.has_packages = picking.move_line_ids.filtered(lambda ml: ml.result_package_id)
picking.has_packages = bool(self.env['stock.move.line'].search_count([('picking_id', '=', picking.id), ('result_package_id', '!=', False)]))
@api.depends('immediate_transfer', 'state')
def _compute_show_check_availability(self):