I have a field that is readonly if the status field of that model is finished, but if the logged user has a specific group, this field would no longer be readonly, how can I validate the user group in the xml, or some other way to achieve this
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I have a field that is readonly if the status field of that model is finished, but if the logged user has a specific group, this field would no longer be readonly, how can I validate the user group in the xml, or some other way to achieve this
Hi,
This can be achieved using two views, one main view and the other one is inherited view(for which we will set user group).
In the main view, you can set the required field attributes for all users and then create an inherited view and set user group for it, then inside this inherited view, you can change the field properties as per need for this user group.
See an use case here: Apply Changes In A View For Particular User Groups In Odoo
Thanks
Please notice that this solution cannot be replicated on Odoo 16 or higher
Hi Pavel,
Try
<field name="comment" attrs="{'readonly': [('state', '!=', 'submit')]}" force_save="1" groups="!base.group_system"/>
<field name="comment" groups="base.group_system"/>
The "!base.group_system" in Odoo restricts access to an element, such as a button or field, to all groups except the "Administration/Settings" group.
This means the element will not be accessible by the users who have Administration/Settings access
Hope it Helps,
Kiran K
I thought it was working fine for me, but it puts the editable field with any user, even though it doesn't have the group I put in the inherited view
id="group_maintenance_petitioner" model="res.groups">
name="name">Maintenance Petitioner
name="category_id" ref="module_category_maintenance"/>
id="df_maintenance_work_order_form_inherit" model="ir.ui.view">
name="name">df.maintenance.work.order.form.inherit
name="model">df.maintenance.work.order
name="groups_id" eval="[(4, ref('group_maintenance_petitioner'))]"/>
name="inherit_id" ref="df_maintenance_work_order_form_view"/>
name="arch" type="xml">
name="employee_ids" position="attributes">
name="attrs">{'readonly': ['|',('state', 'in', ('history','cancelled','posted')),('active', '=', False)]}
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up