From acb9e5fe4908ba0a2ea2be4eccdffaa8a034ae60 Mon Sep 17 00:00:00 2001 From: Swapnesh Shah Date: Sun, 2 May 2021 18:33:29 +0000 Subject: [PATCH] [FIX] mrp: do now allow to select cancelled mo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, User can select Cancelled MO before selecting Product. but it is already blocking since we already have constrains to not allow ubnuilding Cancelled MO. With this commit, We are always showing Done MO. closes odoo/odoo#70316 X-original-commit: 48c0efcc97e35e00ec5803235a89a2c18e821990 Signed-off-by: Rémy Voet --- addons/mrp/models/mrp_unbuild.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index 53731d18a02..328a51123a7 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -4,6 +4,7 @@ from odoo import api, fields, models, _ from odoo.exceptions import AccessError, UserError from odoo.tools import float_compare +from odoo.osv import expression class MrpUnbuild(models.Model): @@ -76,17 +77,12 @@ class MrpUnbuild(models.Model): @api.depends('company_id', 'product_id') def _compute_allowed_mo_ids(self): for unbuild in self: - if unbuild.product_id: - domain = [ + domain = [ ('state', '=', 'done'), - ('product_id', '=', unbuild.product_id.id), - ('company_id', '=', unbuild.company_id.id) - ] - else: - domain = [ - ('state', 'in', ['done', 'cancel']), ('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]