From 59b010ac366e0826fb314b2a89ca47f26906e185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon=20=28ACSONE=29?= Date: Thu, 19 Oct 2017 15:00:52 +0200 Subject: [PATCH] [FIX] sale_stock: refactor badly written method causing performances issues (#20193) --- addons/sale_stock/models/sale_order.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 5ae2b039839..5ce3be00b9a 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -109,11 +109,13 @@ class SaleOrderLine(models.Model): @api.multi @api.depends('product_id') def _compute_qty_delivered_updateable(self): - for line in self: - if line.product_id.type not in ('consu', 'product'): - super(SaleOrderLine, line)._compute_qty_delivered_updateable() - else: - line.qty_delivered_updateable = False + # prefetch field before filtering + self.mapped('product_id') + # on consumable or stockable products, qty_delivered_updateable defaults + # to False; on other lines use the original computation + lines = self.filtered(lambda line: line.product_id.type not in ('consu', 'product')) + lines = lines.with_prefetch(self._prefetch) + super(SaleOrderLine, lines)._compute_qty_delivered_updateable() @api.onchange('product_id') def _onchange_product_id_set_customer_lead(self):