Skip to content

Commit

Permalink
[IMP] cetmix_tower_server: Validation message
Browse files Browse the repository at this point in the history
- Improve validation error message

Task: 4253
  • Loading branch information
GabbasovDinar committed Jan 16, 2025
1 parent ba87a22 commit 016312e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cetmix_tower_server/models/cx_tower_server_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 016312e

Please sign in to comment.