Skip to content
Snippets Groups Projects
Commit 8dcad6e4 authored by Mathieu Walravens's avatar Mathieu Walravens
Browse files

[FIX] delivery: speed up _compute_packages using read_group


Before this commit:
Packages were computed using a for loop, skipping any picking without
any packages.

After this commit:
Packages are computed using a read_group, speeding up the computed
method for large pickings with hundreds of stock move lines.

opw-3461706

closes odoo/odoo#132585

Signed-off-by: default avatarArnold Moyaux (arm) <arm@odoo.com>
parent 8b711569
No related branches found
No related tags found
No related merge requests found
......@@ -77,13 +77,17 @@ class StockPicking(models.Model):
@api.depends('move_line_ids', 'move_line_ids.result_package_id')
def _compute_packages(self):
for package in self:
packs = set()
if self.env['stock.move.line'].search_count([('picking_id', '=', package.id), ('result_package_id', '!=', False)]):
for move_line in package.move_line_ids:
if move_line.result_package_id:
packs.add(move_line.result_package_id.id)
package.package_ids = list(packs)
packages = {
res["picking_id"][0]: set(res["result_package_id"])
for res in self.env["stock.move.line"].read_group(
[("picking_id", "in", self.ids), ("result_package_id", "!=", False)],
["result_package_id:array_agg"],
["picking_id"],
lazy=False, orderby="picking_id asc",
)
}
for picking in self:
picking.package_ids = list(packages.get(picking.id, []))
@api.depends('move_line_ids', 'move_line_ids.result_package_id', 'move_line_ids.product_uom_id', 'move_line_ids.qty_done')
def _compute_bulk_weight(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment