From d7f24257b35ed8e51b21807ddda53a751cf8c045 Mon Sep 17 00:00:00 2001 From: Swapnesh Date: Thu, 6 May 2021 16:50:21 +0000 Subject: [PATCH] [FIX] mrp: display correct uom on by products MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, It was always showing all Unit of Measures in By Product lines. With this commit, We are showing UoMs based on Category of Selected Product's UoM. closes odoo/odoo#70367 Signed-off-by: Rémy Voet --- addons/mrp/models/mrp_bom.py | 15 +++------------ addons/mrp/views/mrp_bom_views.xml | 2 ++ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index a58ad781b38..76dbe43bb20 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -436,7 +436,9 @@ class MrpByProduct(models.Model): product_qty = fields.Float( 'Quantity', default=1.0, digits='Product Unit of Measure', required=True) - product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True) + product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id') + product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True, + domain="[('category_id', '=', product_uom_category_id)]") bom_id = fields.Many2one('mrp.bom', 'BoM', ondelete='cascade', index=True) allowed_operation_ids = fields.One2many('mrp.routing.workcenter', related='bom_id.operation_ids') operation_id = fields.Many2one( @@ -448,14 +450,3 @@ class MrpByProduct(models.Model): """ Changes UoM if product_id changes. """ if self.product_id: self.product_uom_id = self.product_id.uom_id.id - - @api.onchange('product_uom_id') - def onchange_uom(self): - res = {} - if self.product_uom_id and self.product_id and self.product_uom_id.category_id != self.product_id.uom_id.category_id: - res['warning'] = { - 'title': _('Warning'), - 'message': _('The unit of measure you choose is in a different category than the product unit of measure.') - } - self.product_uom_id = self.product_id.uom_id.id - return res diff --git a/addons/mrp/views/mrp_bom_views.xml b/addons/mrp/views/mrp_bom_views.xml index ba283f00b57..03554e5977a 100644 --- a/addons/mrp/views/mrp_bom_views.xml +++ b/addons/mrp/views/mrp_bom_views.xml @@ -17,6 +17,7 @@ +