Skip to Content
Menu
This question has been flagged

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
2
Jan 24
2403
2
Jun 24
3132
2
Aug 23
2829
3
Aug 23
6283
1
Nov 22
2667