Skip to content

Commit

Permalink
[IMP] sale_mrp_bom: disable edition for bom_id field in sale order li…
Browse files Browse the repository at this point in the history
…ne if product's manufacture routes aren't properly settle
  • Loading branch information
rrebollo committed Nov 11, 2024
1 parent 6a04bfc commit fc733ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions sale_mrp_bom/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SaleOrderLine(models.Model):
"('product_id', '=', False)]",
)

can_set_bom_id = fields.Boolean(store=True, compute="_compute_can_set_bom_id")

@api.constrains("bom_id", "product_id")
def _check_match_product_variant_ids(self):
for line in self:
Expand All @@ -32,3 +34,16 @@ def _check_match_product_variant_ids(self):
"Please select BoM that has matched product with the line `{}`"
).format(line_product.name)
)

@api.depends("product_id.route_ids", "is_mto")
def _compute_can_set_bom_id(self):
manufacture_route = self.env.ref(
"mrp.route_warehouse0_manufacture", raise_if_not_found=False
)
for line in self:
can_set_bom_id = False
if line.product_id and manufacture_route:
can_set_bom_id = (
manufacture_route in line.product_id.route_ids and line.is_mto
)
line.can_set_bom_id = can_set_bom_id
4 changes: 4 additions & 0 deletions sale_mrp_bom/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
expr="//field[@name='order_line']//tree//field[@name='name']"
position="after"
>
<field name="can_set_bom_id" invisible="1" />
<field
name="bom_id"
groups="sale_mrp_bom.sale_mrp_bom_group"
context="{'default_product_id': product_id, 'default_product_tmpl_id': product_template_id}"
attrs="{'readonly': [('can_set_bom_id', '=', False)]}"
/>
</xpath>
<xpath
expr="//field[@name='order_line']//form//field[@name='customer_lead']"
position="after"
>
<field name="product_template_id" invisible="1" />
<field name="can_set_bom_id" invisible="1" />
<field
name="bom_id"
groups="sale_mrp_bom.sale_mrp_bom_group"
context="{'default_product_id': product_id, 'default_product_tmpl_id': product_template_id}"
attrs="{'readonly': [('can_set_bom_id', '=', False)]}"
/>
</xpath>
</field>
Expand Down
7 changes: 6 additions & 1 deletion sale_mrp_bom/views/sale_order_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
<field name="inherit_id" ref="sale.view_order_line_tree" />
<field name="arch" type="xml">
<field name="route_id" position="after">
<field name="bom_id" groups="sale_mrp_bom.sale_mrp_bom_group" />
<field name="can_set_bom_id" invisible="1" />
<field
name="bom_id"
groups="sale_mrp_bom.sale_mrp_bom_group"
attrs="{'readonly': [('can_set_bom_id', '=', False)]}"
/>
</field>
</field>
</record>
Expand Down

0 comments on commit fc733ba

Please sign in to comment.