Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2249 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 24
2437
2
thg 6 24
3199
2
thg 8 23
2866
3
thg 8 23
6341
1
thg 11 22
2683