diff options
| author | Ivan Yelizariev <iel@odoo.com> | 2021-04-14 13:43:29 +0000 |
|---|---|---|
| committer | Ivan Yelizariev <iel@odoo.com> | 2021-04-15 10:10:16 +0000 |
| commit | a2d63e8ae5d6bc0e822d12d724b5e3ff5a979cad (patch) | |
| tree | dc3a721b8d892294e2616b6f5b591e60cbc71e85 /addons | |
| parent | 3de9f5953d84f579dc1a4f5ed52e263a1e2c932f (diff) | |
[FIX] mrp: optimize _compute_used_in_bom_count
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 field ``used_in_bom_count`` on a product with ~1000 variants
* Before 9,5 sec
* After 1,5 sec
---
opw-2494423
closes odoo/odoo#69256
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mrp/models/product.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/addons/mrp/models/product.py b/addons/mrp/models/product.py index 400ca6b017e..110e82f0309 100644 --- a/addons/mrp/models/product.py +++ b/addons/mrp/models/product.py @@ -28,7 +28,7 @@ class ProductTemplate(models.Model): def _compute_used_in_bom_count(self): for template in self: template.used_in_bom_count = self.env['mrp.bom'].search_count( - [('bom_line_ids.product_id', 'in', template.product_variant_ids.ids)]) + [('bom_line_ids.product_tmpl_id', '=', template.id)]) def write(self, values): if 'active' in values: @@ -40,7 +40,7 @@ class ProductTemplate(models.Model): def action_used_in_bom(self): self.ensure_one() action = self.env["ir.actions.actions"]._for_xml_id("mrp.mrp_bom_form_action") - action['domain'] = [('bom_line_ids.product_id', 'in', self.product_variant_ids.ids)] + action['domain'] = [('bom_line_ids.product_tmpl_id', '=', self.id)] return action def _compute_mrp_product_qty(self): |
