Skip to content

Commit

Permalink
[FIX] cetmix_tower_server: resolve comments, fix test, create test
Browse files Browse the repository at this point in the history
Task: 4055
  • Loading branch information
tendil committed Jan 15, 2025
1 parent 1f194df commit a70ce93
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 54 deletions.
38 changes: 38 additions & 0 deletions cetmix_tower_server/models/cx_tower_variable_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ def _onchange_variable_id(self):
else:
rec.option_id = None

@api.onchange("variable_id")
def _onchange_variable_id_set_access_level(self):
"""
Automatically set the `access_level` field based on the `variable_id`.
"""
for rec in self:
if rec.variable_id:
rec.access_level = rec.variable_id.access_level

@api.constrains("is_global", "value_char")
def _constraint_global_unique(self):
"""Ensure that there is only one global value exist for the same variable
Expand Down Expand Up @@ -175,6 +184,35 @@ def _compute_variable_ids(self):
["value_char"], force_record=record
)

@api.constrains("access_level", "variable_id")
def _check_access_level_consistency(self):
"""
Ensure that the access level of the variable value is not lower than
the access level of the associated variable.
"""
for rec in self:
if rec.variable_id and rec.access_level < rec.variable_id.access_level:
raise ValidationError(
_(
"The access level for Variable Value '%(value)s' cannot be"
"lower than the access level of its Variable '%(variable)s'.\n"
"Variable Access Level: %(var_level)s\n"
"Variable Value Access Level: %(val_level)s",
value=rec.value_char or "Undefined",
variable=rec.variable_id.name,
var_level=dict(
rec.fields_get(["access_level"])["access_level"][
"selection"
]
)[rec.variable_id.access_level],
val_level=dict(
rec.fields_get(["access_level"])["access_level"][
"selection"
]
)[rec.access_level],
)
)

def _used_in_models(self):
"""Returns information about models which use this mixin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<field name="name">Tower Variable Value: User Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable_value" />
<field name="domain_force">
['&amp;',
[
('access_level', '=', '1'),
('server_id.message_partner_ids', 'in', [user.partner_id.id])]
('server_id.message_partner_ids', 'in', [user.partner_id.id])
]
</field>
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_user'))]" />
</record>
Expand Down
Loading

0 comments on commit a70ce93

Please sign in to comment.