Odoo Help

Welcome!

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

1

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

By
Vaibhav
on 7/10/13, 1:14 PM 4,926 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

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

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

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

Vaibhav
on 8/5/13, 4:41 AM

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

Xsias
on 8/5/13, 6:38 AM

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

Vaibhav
on 8/5/13, 10:09 AM

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

Xsias
on 8/5/13, 10:39 AM

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

Vaibhav
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
4
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 :)

Vaibhav
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

Prakash
on 9/10/13, 7:42 AM
1
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. :)

Vaibhav
on 8/5/13, 4:36 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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