From 016312ec48b6e70c40b12bf9174422a2ef8a2759 Mon Sep 17 00:00:00 2001 From: GabbasovDinar Date: Thu, 16 Jan 2025 11:20:10 +0500 Subject: [PATCH] [IMP] cetmix_tower_server: Validation message - Improve validation error message Task: 4253 --- .../models/cx_tower_server_template.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/cetmix_tower_server/models/cx_tower_server_template.py b/cetmix_tower_server/models/cx_tower_server_template.py index 8edc6c2d..c438b41a 100644 --- a/cetmix_tower_server/models/cx_tower_server_template.py +++ b/cetmix_tower_server/models/cx_tower_server_template.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models -from odoo.exceptions import UserError, ValidationError +from odoo.exceptions import ValidationError class CxTowerServerTemplate(models.Model): @@ -332,12 +332,27 @@ def _prepare_server_values(self, with_template_variables=True, **kwargs): ) if missing_options: - raise UserError( + # Map variable references to their corresponding + # invalid option references. + missing_options_to_variables = { + var_ref: opt_ref + for var_ref, opt_ref in configuration_variable_options.items() + if opt_ref in missing_options + } + # Generate a detailed error message for invalid variable options. + detailed_message = "\n".join( _( - "Option with references '%(references)s' " - "is not found for variables.", - references=", ".join(missing_options), + "Variable reference '%(var_ref)s' has an invalid " + "option reference '%(opt_ref)s'." ) + % {"var_ref": var_ref, "opt_ref": opt_ref} + for var_ref, opt_ref in missing_options_to_variables.items() + ) + raise ValidationError( + _("Some variable options are invalid:\n%(detailed_message)s") + % { + "detailed_message": detailed_message, + } ) # Map variable options to their IDs.