Reputation: 103
Purpose of my model
My model is a help desk and it contains several fields depending on the asked request. When the user chooses his request, the concerned fields about this request appear.
I use a relation between a boolean field and the concerned field (one boolean field per concerned field). In other words, the boolean fields act like switches of visibility for the concerned fields.
When the boolean field is True
, then the concerned field is visible. otherwise, the field is invisible.
My issue
If the user wants to change the request, but he previously filled the fields of the previous request, the previous fields (which some of these must be invisible) still got the user's inputted values. I cannot finalize the asked request if these invisible fields still got values different of their default value.
How I actually do to avoid this problem
Actually, I've created a states table (booleans table) which corresponds to the visibility of every fields that must appear (or not) depending on the asked request.
So if the user has selected a request, at this moment, I set the visibility of my fields by assigning the corresponding boolean values of my states table to boolean fields.
def change_states_of_visibility(self):
boolean_field_1 = False
boolean_field_2 = True
# Other assignation values to boolean fields
Once the visibility set, I set to their default value every fields (concerned or not) with a method.
# When the field has been hidden for some reason
def reset_to_default_value_every_fields(self)
my_field = default_value
# Other fields set to default Value
With this method, I'm now sure that hidden fields are reset to their default value, even they have previously been filled.
As my question said, I would like to know if there is a generic way or better than mine actually, to set to default value every hidden fields.
Upvotes: 1
Views: 541
Reputation: 1524
You need to create one group, for example, i created one group like following.
<record id = "group_admin_only" model="res.groups">
<field name="name">Show to admin only</field>
</record>
Then You can add users in that group to which you want to show that field.
Then add this group to the field which you want to hide like this.
<field name="any_field" groups="your_module.group_admin_only"/>
Now, Only admin user can see this field.
Upvotes: -1