Ir al contenido
Menú
Se marcó esta pregunta

Heey Odoo's

I'm currently working on setting up task management in Odoo 17 for our project teams, and I'm facing a challenge with field-level permissions. Specifically, I want to restrict certain users to only be able to edit the 'stage' field of tasks while keeping other fields locked. Is it possible to achieve this directly from the Odoo UI without modifying the source code? If so, how can I configure these permissions effectively? 

Any guidance or tips would be greatly appreciated!

Avatar
Descartar
Mejor respuesta

Hi,

You can create multiple user groups for your module and use them to restrict access per field

By creating multiple fields in the view:

1. Create a 'stage' field.​

2. Create multiple 'stage' field tags in the view and restrict them accordingly. i.e In the respective View Architecture:
​field name="stage" groups="module_name.user_group_id_1,module_name.user_group_id_2" readonly=1
​​field name="stage" groups="module_name.user_group_id_3" readonly=0

In the above snippet, users belonging to user_group_id_1 and 2 will be able to view the field but cannot edit them. Users belonging to user_group_id_3 will be able to both view and edit the field.


By using a compute method:

1. Create a new boolean compute field that depends on any field with default value.

can_edit = fields.Boolean(compute='_compute_can_edit')

api.depends('any_default_field')
def _compute_can_edit(self):
​for record in self:
​if self.env.user.has_group('module_name.user_group_id_1'):
​record.can_edit = True
​else:
​record.can_edit = False

2. In xml view:

field name="can_edit" invisible="1"
field name="stage" attrs="{'readonly':[('can_edit', '!=', True)]}"

In the above snippet only users belonging to user_group_id_1 will be able to edit the field.


Hope this helps.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ene 24
2402
2
jun 24
3129
2
ago 23
2827
3
ago 23
6283
1
nov 22
2667