[14.0][FIX] bom_attribute_match: BOM unit of measure should match uom of a component_template_id.

This commit is contained in:
Ilyas
2022-08-30 20:36:04 +05:00
parent ec8abb3284
commit cb1008255d
4 changed files with 29 additions and 2 deletions

View File

@@ -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",

View File

@@ -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"

View File

@@ -19,6 +19,13 @@
position="after"
>
<field name="component_template_id" />
<field name="product_uom_id_domain" invisible="1" />
</xpath>
<xpath
expr="//field[@name='bom_line_ids']//field[@name='product_uom_id']"
position="attributes"
>
<attribute name="domain">product_uom_id_domain</attribute>
</xpath>
<xpath
expr="//field[@name='bom_line_ids']//field[@name='product_id']"

View File

@@ -2,3 +2,4 @@
account-analytic
stock-logistics-warehouse
web