From cb1008255dd8779afee17ac3849e214cdbfd34c0 Mon Sep 17 00:00:00 2001 From: Ilyas Date: Tue, 30 Aug 2022 20:36:04 +0500 Subject: [PATCH] [14.0][FIX] bom_attribute_match: BOM unit of measure should match uom of a component_template_id. --- mrp_bom_attribute_match/__manifest__.py | 4 ++-- mrp_bom_attribute_match/models/mrp_bom.py | 19 +++++++++++++++++++ .../views/mrp_bom_views.xml | 7 +++++++ oca_dependencies.txt | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/mrp_bom_attribute_match/__manifest__.py b/mrp_bom_attribute_match/__manifest__.py index 6fa47b638..fa8508f5a 100644 --- a/mrp_bom_attribute_match/__manifest__.py +++ b/mrp_bom_attribute_match/__manifest__.py @@ -4,8 +4,8 @@ "category": "Manufacturing", "author": "Ilyas, Ooops, Odoo Community Association (OCA)", "summary": "Dynamic BOM component based on product attribute", - "depends": ["mrp_account"], - "license": "LGPL-3", + "depends": ["mrp_account", "web_domain_field"], + "license": "AGPL-3", "website": "https://github.com/OCA/manufacture", "data": [ "views/mrp_bom_views.xml", diff --git a/mrp_bom_attribute_match/models/mrp_bom.py b/mrp_bom_attribute_match/models/mrp_bom.py index 0e6d5e7de..e3552e166 100644 --- a/mrp_bom_attribute_match/models/mrp_bom.py +++ b/mrp_bom_attribute_match/models/mrp_bom.py @@ -1,3 +1,4 @@ +import json import logging from odoo import _, api, fields, models @@ -20,6 +21,21 @@ class MrpBomLine(models.Model): match_on_attribute_ids = fields.Many2many( "product.attribute", string="Match on Attributes", readonly=True ) + product_uom_id_domain = fields.Char(compute="_compute_product_uom_id_domain") + + @api.depends("component_template_id", "product_id") + def _compute_product_uom_id_domain(self): + for r in self: + if r.component_template_id: + category_id = r.component_template_id.uom_id.category_id.id + if ( + r.product_uom_id.category_id.id + != r.component_template_id.uom_id.category_id.id + ): + r.product_uom_id = r.component_template_id.uom_id + else: + category_id = r.product_uom_category_id.id + r.product_uom_id_domain = json.dumps([("category_id", "=", category_id)]) @api.onchange("component_template_id") def _onchange_component_template_id(self): @@ -93,6 +109,9 @@ class MrpBomLine(models.Model): ) ) + def write(self, vals): + super(MrpBomLine, self).write(vals) + class MrpBom(models.Model): _inherit = "mrp.bom" diff --git a/mrp_bom_attribute_match/views/mrp_bom_views.xml b/mrp_bom_attribute_match/views/mrp_bom_views.xml index 3b52384cd..90126ae7e 100644 --- a/mrp_bom_attribute_match/views/mrp_bom_views.xml +++ b/mrp_bom_attribute_match/views/mrp_bom_views.xml @@ -19,6 +19,13 @@ position="after" > + + + + product_uom_id_domain