From f15a70863e9eb44d4516c216f80aef67d7983c2f Mon Sep 17 00:00:00 2001 From: David Beal Date: Wed, 13 Sep 2023 12:31:22 +0200 Subject: [PATCH] IMP bom_conf: add constrains model --- mrp_bom_configurable/__manifest__.py | 4 +- mrp_bom_configurable/models/__init__.py | 1 + mrp_bom_configurable/models/input_config.py | 41 ++++------- .../models/input_constraint.py | 19 +++++ mrp_bom_configurable/models/input_line.py | 16 ++++- mrp_bom_configurable/models/mrp_bom.py | 5 ++ .../security/ir.model.access.csv | 1 + .../views/{mrp_view.xml => bom.xml} | 20 ------ mrp_bom_configurable/views/bom_line.xml | 24 +++++++ mrp_bom_configurable/views/input_config.xml | 7 +- .../views/input_constraint.xml | 70 +++++++++++++++++++ mrp_bom_configurable/views/input_line.xml | 4 +- 12 files changed, 157 insertions(+), 55 deletions(-) create mode 100644 mrp_bom_configurable/models/input_constraint.py rename mrp_bom_configurable/views/{mrp_view.xml => bom.xml} (74%) create mode 100644 mrp_bom_configurable/views/bom_line.xml create mode 100644 mrp_bom_configurable/views/input_constraint.xml diff --git a/mrp_bom_configurable/__manifest__.py b/mrp_bom_configurable/__manifest__.py index b02f527287d..f24c8245aca 100644 --- a/mrp_bom_configurable/__manifest__.py +++ b/mrp_bom_configurable/__manifest__.py @@ -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", diff --git a/mrp_bom_configurable/models/__init__.py b/mrp_bom_configurable/models/__init__.py index 7583ac3f979..2c61f41561e 100644 --- a/mrp_bom_configurable/models/__init__.py +++ b/mrp_bom_configurable/models/__init__.py @@ -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 diff --git a/mrp_bom_configurable/models/input_config.py b/mrp_bom_configurable/models/input_config.py index ae4f1d75b25..c09616dc6cd 100644 --- a/mrp_bom_configurable/models/input_config.py +++ b/mrp_bom_configurable/models/input_config.py @@ -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( @@ -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) diff --git a/mrp_bom_configurable/models/input_constraint.py b/mrp_bom_configurable/models/input_constraint.py new file mode 100644 index 00000000000..51c3b970a81 --- /dev/null +++ b/mrp_bom_configurable/models/input_constraint.py @@ -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)] diff --git a/mrp_bom_configurable/models/input_line.py b/mrp_bom_configurable/models/input_line.py index d8cbc7fe6a6..fc4419a5995 100644 --- a/mrp_bom_configurable/models/input_line.py +++ b/mrp_bom_configurable/models/input_line.py @@ -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() @@ -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() @@ -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" diff --git a/mrp_bom_configurable/models/mrp_bom.py b/mrp_bom_configurable/models/mrp_bom.py index 94f936bfbfe..17df59ce33e 100644 --- a/mrp_bom_configurable/models/mrp_bom.py +++ b/mrp_bom_configurable/models/mrp_bom.py @@ -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")] diff --git a/mrp_bom_configurable/security/ir.model.access.csv b/mrp_bom_configurable/security/ir.model.access.csv index d9cfeebc578..324921f20f2 100644 --- a/mrp_bom_configurable/security/ir.model.access.csv +++ b/mrp_bom_configurable/security/ir.model.access.csv @@ -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 diff --git a/mrp_bom_configurable/views/mrp_view.xml b/mrp_bom_configurable/views/bom.xml similarity index 74% rename from mrp_bom_configurable/views/mrp_view.xml rename to mrp_bom_configurable/views/bom.xml index 1384cd907e7..db8f0fa4c76 100644 --- a/mrp_bom_configurable/views/mrp_view.xml +++ b/mrp_bom_configurable/views/bom.xml @@ -59,24 +59,4 @@ - - mrp.bom.line - - - - 1 - - - - - - - - - - diff --git a/mrp_bom_configurable/views/bom_line.xml b/mrp_bom_configurable/views/bom_line.xml new file mode 100644 index 00000000000..c5a710b2768 --- /dev/null +++ b/mrp_bom_configurable/views/bom_line.xml @@ -0,0 +1,24 @@ + + + + + mrp.bom.line + + + + 1 + + + + + + + + + + + diff --git a/mrp_bom_configurable/views/input_config.xml b/mrp_bom_configurable/views/input_config.xml index ee34c47fcba..54867ba3d5e 100644 --- a/mrp_bom_configurable/views/input_config.xml +++ b/mrp_bom_configurable/views/input_config.xml @@ -104,16 +104,17 @@ - Configurator + Configured Products input.config tree,form + + - diff --git a/mrp_bom_configurable/views/input_constraint.xml b/mrp_bom_configurable/views/input_constraint.xml new file mode 100644 index 00000000000..57719677b87 --- /dev/null +++ b/mrp_bom_configurable/views/input_constraint.xml @@ -0,0 +1,70 @@ + + + + + input.constraint + +
+
+ + + + + + + + + +
+ + +
+ + + + + + input.constraint + + + + + + + + + input.constraint + + + + + + + + + + + + input.constraint + + + + + + + + + + Input Constraints + input.constraint + tree,form,pivot + + + + + diff --git a/mrp_bom_configurable/views/input_line.xml b/mrp_bom_configurable/views/input_line.xml index 577de3e8579..04b29a8c68f 100644 --- a/mrp_bom_configurable/views/input_line.xml +++ b/mrp_bom_configurable/views/input_line.xml @@ -15,8 +15,10 @@ title="Configure" /> - + + +