Skip to content

Commit

Permalink
IMP mrp_bom_conf: use widget domain
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Sep 11, 2023
1 parent 9808077 commit 495dc5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
16 changes: 14 additions & 2 deletions mrp_bom_configurable/models/mrp_bom_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from odoo import fields, models
from odoo import _, fields, models
from odoo.tools.safe_eval import safe_eval

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -50,6 +50,18 @@ def execute(self, values):
if not self.domain:
return True
else:
domain = safe_eval(self.domain)
# TODO need to work with only one '=' here
domain = safe_eval(self.domain.replace("=", "=="))

return self.execute_domain(domain, values)

def ui_update_domain(self):
self.ensure_one()
return {
"name": _(f"Domain for {self.product_id}"),
"type": "ir.actions.act_window",
"res_model": "mrp.bom.line",
"res_id": self.id,
"view_mode": "form",
"target": "current",
}
29 changes: 23 additions & 6 deletions mrp_bom_configurable/views/mrp_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="mrp_bom_form_view" model="ir.ui.view">
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
Expand All @@ -8,10 +9,16 @@
<field name="configuration_type" />
</field>
<xpath
expr="//field[@name='bom_line_ids']/tree/field[@name='product_qty']"
expr="//field[@name='bom_line_ids']/tree/field[@name='product_uom_id']"
position="after"
>
<field name="domain" />
<field name="domain" readonly="1" />
<button
name="ui_update_domain"
type="object"
class="oi oi-launch"
title="Update domain"
/>
<field name="condition" />
</xpath>
</field>
Expand Down Expand Up @@ -56,10 +63,20 @@
<field name="model">mrp.bom.line</field>
<field name="inherit_id" ref="mrp.mrp_bom_line_view_form" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="domain" />
<field name="condition" optional="hide" />
</field>
<xpath expr="//form" position="attributes">
<attribute name="edit">1</attribute>
</xpath>
<xpath expr="//group" position="after">
<group name="domain" string="Domain">
<field
name="domain"
widget="domain"
options="{'model': 'input.line'}"
/>
<field name="condition" />
</group>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 495dc5e

Please sign in to comment.