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

I have a model like :

class Mymodel(models.model):
_name= mymodel
field_1 = fields.char()
field_2 = fields.char()
field_3 = fields.char()

And i have 2 groups say group1 and group2 . group1 users can only read field_1 and field_2 

but can modify field_3 . group2 users can edit field_1 only , other fields only read permission . 

How to achieve this.

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

Hi  ​T Ketaki Debadarshini,

You can achieve this by using following code

In Python

from lxml import etree


@api.model
def fields_view_get(self, view_id='you_form_view_id', view_type='form', toolbar=False, submenu=False):
res = super(ClassName, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
doc = etree.XML(res['arch'])
if self.env.user.has_group('group1'):
for node in doc.xpath("//field[@name='field1']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
elif self.env.user.has_group('group2'):
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field3']"):
node.set('modifiers', '{"readonly": true}')
res['arch'] = etree.tostring(doc)
return res





Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you Gokulakrishnan Murugesan.. It worked. :)

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 23
2445
2
thg 9 19
4505
2
thg 7 23
5703
3
thg 1 24
12751
2
thg 3 25
5882