This question has been flagged
3 Replies
13944 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

Avatar
Discard
Best Answer

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.

EDIT :

Here some links about ir_model_access :

https://accounts.openerp.com/forum/Help-1/question/12430

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 :

http://forum.openerp.com/forum/topic16596.html

http://stackoverflow.com/questions/15966676/openerp-7-access-rights-for-user-roles

Avatar
Discard
Author

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

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

Author

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

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

Author

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

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

Best Answer

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...

Avatar
Discard
Author

Thank you :)

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

Best Answer

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

thank you..

Avatar
Discard
Author

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. :)