[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#69341 X-original-commit: a2d63e8ae5d6bc0e822d12d724b5e3ff5a979cad Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com> Signed-off-by: Ivan Yelizariev // IEL <yelizariev@users.noreply.github.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user