From 038fdcabe052d4621ebae87f842949b0c2499356 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Wed, 14 Apr 2021 13:43:29 +0000 Subject: [PATCH] [FIX] mrp: optimize _compute_used_in_bom_count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit previous implementation works slowly for products with many variants. Performance Test ================ * ~5 K product.template * ~14 K product.variants * ~12 K mrp.bom * ~414 K mrp.bom.line Reading time for the field on a product with ~1000 variants Measuring total request time: * Before 9,5 sec * After: ** without module upgrade 1,5 sec ** with module upgrade 0,3 sec Measuring query execution in psql: * Before 7,2 sec * After: ** without module upgrade 0,7 sec ** with module upgrade 0,001 sec --- opw-2494423 closes odoo/odoo#69293 Signed-off-by: Rémy Voet --- addons/mrp/models/mrp_bom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index 8b53d0e4710..a58ad781b38 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -288,7 +288,7 @@ class MrpBomLine(models.Model): return self.env['uom.uom'].search([], limit=1, order='id').id product_id = fields.Many2one('product.product', 'Component', required=True, check_company=True) - product_tmpl_id = fields.Many2one('product.template', 'Product Template', related='product_id.product_tmpl_id') + product_tmpl_id = fields.Many2one('product.template', 'Product Template', related='product_id.product_tmpl_id', store=True, index=True) company_id = fields.Many2one( related='bom_id.company_id', store=True, index=True, readonly=True) product_qty = fields.Float(