简体   繁体   中英

how to make many2one field readonly for user which is under specific group in open erp7?

I created module named hr_th having security group "group_thw_emp" I have field "employee_id" which is many2one field refer to hr_employee class. I tried following code in my xml

<field name="employee_id" attrs= "{'readonly': [('groups','=','hr_th.group_thw_emp')]}"/>

but I get error as :

Uncaught Error: Unknown field groups in domain [['groups','=','hr_th.group_thw_emp']]

This is a slightly tricky one. Ideally you would do something like

attrs = {'readonly': [('employee_id.groups', 'contains', 'hr_th.group_thw_emp')]}

But as far as I know you can't do this. I don't believe the attribute expression evaluator supports contains.

The way I have worked around it is to extended or change the model and add a functional field that returns true if the employee is a member of the group you want and use it like this.

<field name="employee_is_in_thw_emp" invisible="1" />
<field name="employee_id" attrs="{'readonly': [('employee_is_in_thw_emp', '=', True)]}" />

This isn't great as you could end up with a lot of functional fields but I haven't found a better way yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM