This question has been flagged

Hi I need to restrict the write access of a field in res.partner form. Only admin should have the access to write the field. The field should be readonly  for all other users. How can I make it possible.

Thanks in Advance.

Avatar
Discard
Best Answer

Hi! The following code is an example how to use fields_view_get:

@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
context = self._context or {}
res = super(Partner, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=False)
if not self.env.user.has_group('base.user_root'):
doc = etree.XML(res['arch'])
# The field you want to modify the attribute
node = doc.xpath("//field[@name='email']")[0]
node.set('readonly', '1')
setup_modifiers(node, res['fields']['email'])
res['arch'] = etree.tostring(doc)
return res
return res
Avatar
Discard