summaryrefslogtreecommitdiff
path: root/addons/mrp
diff options
context:
space:
mode:
authorRémy Voet (ryv) <ryv@odoo.com>2020-12-31 09:20:07 +0000
committerRémy Voet (ryv) <ryv@odoo.com>2021-01-21 13:52:41 +0000
commitcefb14f79185bc135d6717e7ca8dbe5d23856371 (patch)
treec4236299f4939afa2dc2a183255f04b1a5563e22 /addons/mrp
parenta8dd0655b1e318a6940b5dd1708952043349de4e (diff)
[FIX] mrp: add indexes on highly search fields
Add two indexes (on `product_id` and `product_tmpl_id`) on the `mrp.bom` model to speed up `_bom_find` which is highly used and it uses always the `product_tmpl_id` and sometime the `product_id` in the search domain. Performance Gain: With a DB with 2K BoM, a `_bom_find` search (`product_id` and `product_tmpl_id` are in domain): The SQL execution time is +- 5 times faster. task-2390516 closes odoo/odoo#63922 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Diffstat (limited to 'addons/mrp')
-rw-r--r--addons/mrp/models/mrp_bom.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index 2c1cca166a0..68b84e1f212 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -30,11 +30,11 @@ class MrpBom(models.Model):
default='normal', required=True)
product_tmpl_id = fields.Many2one(
'product.template', 'Product',
- check_company=True,
+ check_company=True, index=True,
domain="[('type', 'in', ['product', 'consu']), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", required=True)
product_id = fields.Many2one(
'product.product', 'Product Variant',
- check_company=True,
+ check_company=True, index=True,
domain="['&', ('product_tmpl_id', '=', product_tmpl_id), ('type', 'in', ['product', 'consu']), '|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="If a product variant is defined the BOM is available only for this product.")
bom_line_ids = fields.One2many('mrp.bom.line', 'bom_id', 'BoM Lines', copy=True)