Skip to content

Commit

Permalink
IMP bom_conf: add constrains model
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Sep 13, 2023
1 parent cdadd8b commit 3b086aa
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 55 deletions.
4 changes: 3 additions & 1 deletion mrp_bom_configurable/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"data": [
"views/input_config.xml",
"views/input_line.xml",
"views/mrp_view.xml",
"views/input_constraint.xml",
"views/bom.xml",
"views/bom_line.xml",
"report/report.xml",
"report/bom_configurable.xml",
"security/ir.model.access.csv",
Expand Down
1 change: 1 addition & 0 deletions mrp_bom_configurable/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import input_config
from . import input_line
from . import input_constraint
from . import mrp_bom
from . import mrp_bom_line

Expand Down
41 changes: 14 additions & 27 deletions mrp_bom_configurable/models/input_config.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
from odoo import fields, models
from odoo import api, fields, models


class InputConfig(models.Model):
_name = "input.config"
_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)]
_description = "Header configuration scenari"

name = fields.Char(required=True)
date = fields.Date(default=fields.Date.today())
bom_id = fields.Many2one(
comodel_name="mrp.bom",
string="Configurable Product",
required=True,
domain=_compute_bom_domain,
comodel_name="mrp.bom", string="Configurable Product", required=True
)
bom_domain = fields.Binary(compute="_compute_bom_domain")
state = fields.Selection(
Expand All @@ -52,6 +28,17 @@ def _compute_bom_domain(self):
line_ids = fields.One2many(comodel_name="input.line", inverse_name="config_id")
line_count = fields.Integer(string="Lines", compute="_compute_line_count")

@api.depends("bom_id")
def _compute_bom_domain(self):
domain = self.env["mrp.bom"]._get_bom_domain_for_config()
boms = self.env["mrp.bom"].search(domain)
for rec in self:
ids = boms and boms.ids or [False]
rec.bom_domain = [("id", "in", ids)]

def _get_bom_domain(self):
return [("configuration_type", "=", "variable")]

def _compute_line_count(self):
for rec in self:
rec.line_count = len(rec.line_ids)
Expand Down
19 changes: 19 additions & 0 deletions mrp_bom_configurable/models/input_constraint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import api, fields, models


class InputConstraint(models.Model):
_name = "input.constraint"
_inherit = ["mail.thread"]
_rec_name = "bom_id"
_description = "Contains input data constraints"

bom_id = fields.Many2one(comodel_name="mrp.bom")
bom_domain = fields.Binary(compute="_compute_bom_domain")

@api.depends("bom_id")
def _compute_bom_domain(self):
domain = self.env["mrp.bom"]._get_bom_domain_for_config()
boms = self.env["mrp.bom"].search(domain)
for rec in self:
ids = boms and boms.ids or [False]
rec.bom_domain = [("id", "in", ids)]
16 changes: 13 additions & 3 deletions mrp_bom_configurable/models/input_line.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from odoo import fields, models
from odoo import api, fields, models


class Inputline(models.Model):
_name = "input.line"
_description = "Input data for bom configuration"
_description = "Line configuration scenari"

name = fields.Char()
sequence = fields.Integer()
Expand All @@ -13,7 +13,13 @@ class Inputline(models.Model):
)
config_id = fields.Many2one(comodel_name="input.config", required=True)
count = fields.Integer(default=1)
comment = fields.Char()
alert = fields.Text(help="Outside limit configuration is reported here")
checked = fields.Boolean(
compute="_compute_check",
store=True,
help="If checked, the configuration have been evaluate",
)
comment = fields.Text()

def ui_clone(self):
self.ensure_one()
Expand All @@ -23,3 +29,7 @@ def ui_clone(self):
def ui_configure(self):
# TODO
pass

@api.depends("bom_id", "count")
def _compute_check(self):
"You need to override this method in your custom config to trigger adhoc checks"
5 changes: 5 additions & 0 deletions mrp_bom_configurable/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ def check_domain(self, values):
result.append(line)

return result

@classmethod
def _get_bom_domain_for_config(cls):
"You may override me"
return [("configuration_type", "=", "variable")]
1 change: 1 addition & 0 deletions mrp_bom_configurable/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
input_config_base,Base input config,mrp_bom_configurable.model_input_config,base.group_user,1,1,1,1
input_line_base,Base input line,mrp_bom_configurable.model_input_line,base.group_user,1,1,1,1
input_constraint_base,Base input constraint,mrp_bom_configurable.model_input_constraint,base.group_user,1,1,1,1
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,4 @@
</field>
</record>

<record id="mrp_bom_line_view_form" model="ir.ui.view">
<field name="model">mrp.bom.line</field>
<field name="inherit_id" ref="mrp.mrp_bom_line_view_form" />
<field name="arch" type="xml">
<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>
24 changes: 24 additions & 0 deletions mrp_bom_configurable/views/bom_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="mrp_bom_line_view_form" model="ir.ui.view">
<field name="model">mrp.bom.line</field>
<field name="inherit_id" ref="mrp.mrp_bom_line_view_form" />
<field name="arch" type="xml">
<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>
7 changes: 4 additions & 3 deletions mrp_bom_configurable/views/input_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@
</record>

<record id="input_config_action" model="ir.actions.act_window">
<field name="name">Configurator</field>
<field name="name">Configured Products</field>
<field name="res_model">input.config</field>
<field name="view_mode">tree,form</field>
</record>

<menuitem id="configurator_menu" name="🔩" parent="mrp.menu_mrp_root" />

<menuitem
id="input_config_menu"
parent="mrp.menu_mrp_root"
parent="configurator_menu"
action="input_config_action"
/>


</odoo>
70 changes: 70 additions & 0 deletions mrp_bom_configurable/views/input_constraint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<odoo>


<record id="input_constraint_form" model="ir.ui.view">
<field name="model">input.constraint</field>
<field name="arch" type="xml">
<form>
<header />
<sheet>
<group name="main">
<group name="left">
<field name="bom_domain" invisible="1" />
<field name="bom_id" domain="bom_domain" />
</group>
<group name="right" />
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
<field name="message_ids" widget="mail_thread" />
</div>
</form>
</field>
</record>

<record id="input_constraint_tree" model="ir.ui.view">
<field name="model">input.constraint</field>
<field name="arch" type="xml">
<tree>
<field name="bom_id" />
</tree>
</field>
</record>

<record id="input_constraint_search" model="ir.ui.view">
<field name="model">input.constraint</field>
<field name="arch" type="xml">
<search>
<field name="bom_id" />
<group expand="0" string="Group By">
<filter name="bom_id" context="{'group_by': 'bom_id'}" />
</group>
</search>
</field>
</record>

<record id="input_constraint_pivot" model="ir.ui.view">
<field name="model">input.constraint</field>
<field name="arch" type="xml">
<pivot>
<!-- customize with your own fields -->
<field name="bom_id" type="row" />
</pivot>
</field>
</record>

<record id="input_constraint_action" model="ir.actions.act_window">
<field name="name">Input Constraints</field>
<field name="res_model">input.constraint</field>
<field name="view_mode">tree,form,pivot</field>
</record>

<menuitem
id="input_constraint_menu"
sequence="15"
parent="mrp_bom_configurable.configurator_menu"
action="input_constraint_action"
/>

</odoo>
4 changes: 3 additions & 1 deletion mrp_bom_configurable/views/input_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
title="Configure"
/>
<field name="name" />
<field name="comment" optional="hide" />
<field name="count" />
<field name="alert" optional="show" />
<field name="comment" optional="show" />
<field name="checked" optional="hide" />
<field name="config_id" invisible="1" />
</tree>
</field>
Expand Down

0 comments on commit 3b086aa

Please sign in to comment.