我创建了一个名为“HM-1”的自定义标题菜单
我创建了一个名为'Menu 1'的菜单 在“菜单1”中,我创建了3个字段,名为field_1 fileds_2 filed_3。
I created a 'User' and i have two users now
1. Admin
2. User
我的问题是'如何创建一个字段(field_3)'用户'和'管理员'可在Openerp-7中编辑 “用户”中的剩余字段应该只读取field_3应该是可编辑的。
怎么做?
答案 0 :(得分:1)
我首先想到的是覆盖 fields_view_get ,并根据 self.env.user 的组更改field_1和field_2的readonly和modifiers属性。当然,您需要将用户分配给特定组,与管理员不同。
class example_class(models.Model):
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(example_class, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
group = self.pool['ir.model.data'].xmlid_to_object(cr, uid, 'your_group', raise_if_not_found=True, context=context)
if view_type == 'form' and group in self.env.user.groups_id:
doc = etree.XML(res['arch'])
#this for cycle must be repeated for each field you need to make readonly
for node in doc.xpath("//field[@name='field_2']"):
if 'modifiers' in node.attrib:
text = node.attrib['modifiers']
j = json.loads(text)
j['readonly'] = '1'
else:
j = {'readonly': '1'}
node.attrib['modifiers'] = json.dumps(j)
res['arch'] = etree.tostring(doc)
return res