From a23afea36da933cc82c5e51cc76be99e6f399181 Mon Sep 17 00:00:00 2001 From: "matthias.lotz" Date: Sat, 21 Jun 2025 20:53:57 +0200 Subject: [PATCH] fixed Color Picker in machine_area_views --- models/ows_models.py | 50 +++++++++++++++++++++++++++++++++--- views/machine_area_views.xml | 6 +++-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/models/ows_models.py b/models/ows_models.py index e2fea6e..c19a086 100644 --- a/models/ows_models.py +++ b/models/ows_models.py @@ -377,15 +377,57 @@ class OwsUser(models.Model): ] +AVAILABLE_COLORS = [ + ('#000000', 'schwarz'), + ('#ff0000', 'Rot'), + ('#E91E63', 'Pink'), + ('#9C27B0', 'Lila'), + ('#3F51B5', 'Indigo'), + ('#0000ff', 'Blau'), + ('#008000', 'Grün'), + ('#ffff00', 'Gelb'), + ('#FF9800', 'Orange'), + ('#795548', 'Braun'), + ('#ffffff', 'Weiss'), +] + class OwsMachineArea(models.Model): _name = 'ows.machine.area' - _table = "ows_machine_area" + _table = 'ows_machine_area' _description = 'OWS: Maschinenbereich' _order = 'name' - name = fields.Char(required=True, translate=True) - #color = fields.Integer(string="Farbe") - color_hex = fields.Char(string="Farbe (Hex)", help="Hex-Farbcode wie #FF0000 für Rot") + name = fields.Char(string="Name", required=True, translate=True) + + color_hex = fields.Selection( + selection=AVAILABLE_COLORS, + string="Farbe (Hex)", + required=True, + ) + + color_hex_value = fields.Char( + string="Farbcode", + compute='_compute_color_hex_value', + store=False + ) + + color_name = fields.Char( + string="Farbname", + compute='_compute_color_name', + store=False + ) + + @api.depends('color_hex') + def _compute_color_hex_value(self): + for rec in self: + rec.color_hex_value = rec.color_hex or '' + + @api.depends('color_hex') + def _compute_color_name(self): + label_dict = dict(AVAILABLE_COLORS) + for rec in self: + rec.color_name = label_dict.get(rec.color_hex, 'Unbekannt') + class OwsMachine(models.Model): diff --git a/views/machine_area_views.xml b/views/machine_area_views.xml index 88e9956..b2232b7 100644 --- a/views/machine_area_views.xml +++ b/views/machine_area_views.xml @@ -17,7 +17,8 @@ - + + @@ -30,7 +31,8 @@
- + +