跳至內容
選單
此問題已被標幟

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.

頭像
捨棄
最佳答案

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
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
11月 19
3808
2
8月 23
2123
0
2月 21
3108
0
11月 20
2082
1
7月 20
3633