Skip to content

Commit

Permalink
IMP mrp_bom_conf: bom_id domain
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Sep 11, 2023
1 parent f3e2eab commit 9808077
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
29 changes: 27 additions & 2 deletions mrp_bom_configurable/models/input_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@ class InputConfig(models.Model):
_inherit = ["mail.thread", "mail.activity.mixin"]
_description = "Product configuration scenari"

def _compute_bom_domain(self):
var_boms = self.env["mrp.bom"].search([("configuration_type", "=", "variable")])
var_tmpl = var_boms.mapped("product_tmpl_id")
products = self.env["product.product"].search(
[("product_tmpl_id", "in", var_tmpl.ids)]
)
compon_tmpl = (
self.env["mrp.bom.line"]
.search([("product_id", "=", products.ids)])
.mapped("product_id.product_tmpl_id")
)
tmpls = var_tmpl - compon_tmpl
boms = self.env["mrp.bom"].search(
[
("configuration_type", "=", "variable"),
("product_tmpl_id", "in", tmpls.ids),
]
)
for rec in self:
rec.bom_domain = [("id", "in", boms.ids)]

name = fields.Char(required=True)
date = fields.Date(string="Date", default=fields.Date.today())
date = fields.Date(default=fields.Date.today())
bom_id = fields.Many2one(
comodel_name="mrp.bom", string="Configurable Product", required=True
comodel_name="mrp.bom",
string="Configurable Product",
required=True,
domain=_compute_bom_domain,
)
bom_domain = fields.Binary(compute="_compute_bom_domain")
state = fields.Selection(
selection=[
("draft", "Draft"),
Expand Down
6 changes: 2 additions & 4 deletions mrp_bom_configurable/views/input_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
</group>
<group name="config">
<group name="left">
<field
name="bom_id"
domain="[('configuration_type', '=', 'variable')]"
/>
<field name="bom_domain" invisible="1" />
<field name="bom_id" domain="bom_domain" />
</group>
<!-- Set custom config fields in these groups -->
<group name="right" />
Expand Down

0 comments on commit 9808077

Please sign in to comment.