Odoo Help


How to make many2one field readonly for user which is under specific group?

on 7/10/13, 1:14 PM 6,301 views

Hello, 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']]

Thank you in advance

On 8/2/13, 12:53 PM

You can add a line in the ir.model.access.csv of the concerned module like that :

id  name    model_id:id group_id:id perm_read   perm_write  perm_create perm_unlink

access_hr_th_group_thw_emp  hr.th.employee_id       hr.model_hr_th  group_thw_emp   1   0   0   0

I'm not sure about my line cause i don't know your groups and module, but you can inspire yourself with any ir.model.access.csv on the base code.


Here some links about ir_model_access :


In this link you can read :

For :

id  name    model_id/id group_id/id perm_read   perm_write  
perm_create perm_unlink
model_bpl_worker_manager    bpl_worker  model_bpl_worker    
group_checkroll_manager 1   1   1   1
  • id = unique identify for the permission (Example: MY_MODULE_res_partner_manager)
  • name = unique name for the permission (Example: res_partner manager)
  • model_id/id = the model unique name of the class you want apply permission on (Example model_res_partner)
  • group_id/id = group permission apply on (yopu can define it in xml group file or call an existing group with syntax module.group_id)
  • perm_read,perm_write,perm_create,perm_unlink = the 4 values for the relative permission to read, write,create,unlink record on defined class. 1 is True (you can do this action) and 0 is Faslse (you can't)

A simple way to understand this file is to read an existing csv in some OpenERP base module like sale, account, product, etc...

Some useful link: http://www.zbeanztech.com/blog/security-openerp

I can give you others links likes :



I think module name is hr_employee. hr_th is My addons Folder name Innside that i created my new module which is inherited from hr_employee

on 8/5/13, 4:41 AM

I've edited my answer with some links about ir_model_access.

on 8/5/13, 6:38 AM

Thank you, I also wanted to know that can we give field level Security through .csv file?

on 8/5/13, 10:09 AM

I've never used yet, but i've heard that yes, we can.

on 8/5/13, 10:39 AM

How? Because which may be act as optional for functional field way to do same task?

on 8/5/13, 11:22 AM

This does not answer the question: it doesn't address field-level security.

Daniel Reis
on 11/13/13, 5:59 AM
Mario Arias Badila
On 8/5/13, 10:01 PM

You can also do this on your python file, like this:

'employee': fields.char(string='Employee name',read=['base.group_sale_salesman'],write=['base.group_sale_manager']),

This will give group_sale_salesman read-only permissions, and group_sale_manager write permissions...

Thank you :)

on 8/6/13, 3:29 AM

Hello Mario, read only and write only Permissions its working fine. Is there any way to show message to the End user for example other user try to modify field its shows "Sorry, you are not allowed to change this Field Data" Thanks

on 9/10/13, 7:42 AM
Ali Ravani
On 8/3/13, 9:14 AM

Try this <field name="employee_id" readonly="1" group="hr_th.group_thw_emp"/>

thank you..

This is not working.And if we give group to any field then that field is visible only for that group.So I got Solution For this by creating one functional boolean Field depending on its Value In xml I gave condition of readonly. :)

on 8/5/13, 4:36 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 7/10/13, 1:14 PM
Seen: 6301 times
Last updated: 3/16/15, 8:10 AM