From 2461543aad1c57b232eaaeb4788f550d10ef857c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Wed, 2 Jun 2021 09:23:19 +0000 Subject: [PATCH] [FIX] mrp: make the unbuild form more scalable Making a dynamic domain with a `allowed_xxx_ids` field is a bad idea when the domain doesn't filter out the most of records. It can create a performance issue, if the `allowed_xxx_ids` contains too much ids, then a lot of data will be exchange to/from server for each onchange which slows down all the form views. task-2558097 --- addons/mrp/models/mrp_unbuild.py | 18 +----------------- addons/mrp/views/mrp_unbuild_views.xml | 2 -- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index 696f605c220..0b028e0b9d8 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -45,7 +45,7 @@ class MrpUnbuild(models.Model): states={'done': [('readonly', True)]}, check_company=True) mo_id = fields.Many2one( 'mrp.production', 'Manufacturing Order', - domain="[('id', 'in', allowed_mo_ids)]", + domain="[('state', '=', 'done'), ('company_id', '=', company_id), ('product_id', '=?', product_id)]", states={'done': [('readonly', True)]}, check_company=True) mo_bom_id = fields.Many2one('mrp.bom', 'Bill of Material used on the Production Order', related='mo_id.bom_id') lot_id = fields.Many2one( @@ -72,22 +72,6 @@ class MrpUnbuild(models.Model): state = fields.Selection([ ('draft', 'Draft'), ('done', 'Done')], string='Status', default='draft') - allowed_mo_ids = fields.One2many('mrp.production', compute='_compute_allowed_mo_ids') - - @api.depends('company_id', 'product_id') - def _compute_allowed_mo_ids(self): - for unbuild in self: - domain = [ - ('state', '=', 'done'), - ('company_id', '=', unbuild.company_id.id) - ] - if unbuild.product_id: - domain = expression.AND([domain, [('product_id', '=', unbuild.product_id.id)]]) - allowed_mos = self.env['mrp.production'].search_read(domain, ['id']) - if allowed_mos: - unbuild.allowed_mo_ids = [mo['id'] for mo in allowed_mos] - else: - unbuild.allowed_mo_ids = False @api.onchange('company_id') def _onchange_company_id(self): diff --git a/addons/mrp/views/mrp_unbuild_views.xml b/addons/mrp/views/mrp_unbuild_views.xml index 28af1a01d53..81a58bba28f 100644 --- a/addons/mrp/views/mrp_unbuild_views.xml +++ b/addons/mrp/views/mrp_unbuild_views.xml @@ -116,7 +116,6 @@ - @@ -155,7 +154,6 @@ -