From 38d4a641f14bf8ea9246159afd172a6d87769b2d Mon Sep 17 00:00:00 2001 From: git_admin Date: Mon, 27 Apr 2026 08:15:51 +0000 Subject: [PATCH] Tower: upload cetmix_tower_server 16.0.3.0.1 (via marketplace) --- .../cx_tower_custom_variable_value_mixin.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 addons/cetmix_tower_server/models/cx_tower_custom_variable_value_mixin.py diff --git a/addons/cetmix_tower_server/models/cx_tower_custom_variable_value_mixin.py b/addons/cetmix_tower_server/models/cx_tower_custom_variable_value_mixin.py new file mode 100644 index 0000000..745b459 --- /dev/null +++ b/addons/cetmix_tower_server/models/cx_tower_custom_variable_value_mixin.py @@ -0,0 +1,52 @@ +from odoo import api, fields, models + + +class CxTowerCustomVariableValueMixin(models.AbstractModel): + """ + Custom variable values. + """ + + _name = "cx.tower.custom.variable.value.mixin" + _description = "Custom variable values" + + variable_id = fields.Many2one( + "cx.tower.variable", + ) + variable_type = fields.Selection(related="variable_id.variable_type", readonly=True) + value_char = fields.Char( + string="Value", + compute="_compute_value_char", + readonly=False, + store=True, + help="Automatically populated from selected option. " + "Manual edits will be overwritten when option changes.", + ) + option_id = fields.Many2one( + "cx.tower.variable.option", domain="[('variable_id', '=', variable_id)]" + ) + + variable_value_id = fields.Many2one("cx.tower.variable.value") + required = fields.Boolean( + related="variable_value_id.required", + readonly=True, + store=True, + ) + + @api.depends("option_id", "variable_id", "variable_type") + def _compute_value_char(self): + """ + Compute value_char based on selected option for option-type variables. + For non-option variables, value_char is cleared to allow manual input. + """ + for rec in self: + if rec.variable_id and rec.variable_type == "o" and rec.option_id: + rec.value_char = rec.option_id.value_char + else: + rec.value_char = "" + + @api.onchange("variable_id") + def _onchange_variable_id(self): + """ + Reset option_id when variable changes. + """ + self.update({"option_id": None})