Odoo Help


How to set a field readonly for a employee group ?

on 5/15/15, 12:48 AM 3,655 views

Hi all,

I have a custom module in hr , I want to set  'remarks' field set as read only for employees, and  I want to set read and write operation access  for manager user .How to achieve this task?

This is my code---------

lass hr_general(osv.osv):

_name = 'hr.general'

_columns = {


'state': fields.selection([('draft', 'To Submit'), ('reject', 'Rejected'), ('validate_hr', 'HR Approved'),('validate_mgr','Manager Approved')],'State'),







'state':lambda *a: 'draft',

'date_issue': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),

'name': lambda s, cr, uid, c: uid,


xml ---------------------

<record model="ir.ui.view" id="hrgeneral_form_view">

<field name="name">hr.general.form</field>

<field name="model">hr.general</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form string="Genaral" version="7.0">


<button name="action_button_manager" class="oe_highlight" states="draft" string="Manager Approval" type="object" groups="base.group_hr_user"/>

<button name="action_button_reject" string="Reject" type="object" groups="base.group_hr_user"/>

<button name="action_button_validate" states="validate_mgr" class="oe_highlight" string="HR Approval" type="object" groups="base.group_hr_user"/>

<button name="action_button_draft" string="Reset to Draft" type="object" groups="base.group_hr_user"/>

<field name="state" widget="statusbar" statusbar_visible="draft,reject,validate_hr,validate_mgr" statusbar_colors='{"draft":"blue","reject":"blue","validate_hr":"blue","validate_mgr":"blue"}'/>




<field name="name"/>

<field name="description"/>

<field name="date_issue"/>

<field name="details"/>

<field name="remarks"/></group>






 These are the existing groups ,so how to apply this groups to  my code  groups="base.group_hr_manager,base.group_hr_user,base.group_user"


Hello deep, hr.general.form hr.general form

hr.general.form hr.general <xpath expr="//field[@name='remarks']" position="attributes"> 0 when user have access rights for groups "group_hr_manager" after the fields "remarks" is editable othewize it's not editable

Jaydeep Barot (jar)
on 5/15/15, 2:55 AM

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
| 5 5 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 5/15/15, 1:21 AM

Sample code with similar scenario available here

First, set remarks as READONLY in XML and add this view in your XML file

 <record model="ir.ui.view" id="hr_manager_form_view">
	<field name="name">hr.general.form</field>
	<field name="model">hr.general</field>
	<field name="inherit_id" ref="hrgeneral_form_view" />
	<field name="groups_id" eval="[(6,0,[ref('base.group_hr_manager')])]" />
	<field name="arch" type="xml">
		<xpath expr="//field[@name='remarks']" position="attributes">
			<attribute name="readonly">0</attribute>

i have some daught why you are using inherit_id, this is not an independent model not depending any existing model like (hr.employee ..) i just want to add read only for employees and all other permission given to manager.....

on 5/15/15, 1:28 AM

This is done to overwrite the field properties/attributes with a new one but with a group linked to it. Thus the changes are only applied if the group is enabled for the user. Normally, if we have to do a change in XML, we normally inherit the view and do so, the same logic applies here.

Atchuthan - Technical Consultant, Sodexis Inc
on 5/15/15, 1:47 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

2 follower(s)


Asked: 5/15/15, 12:48 AM
Seen: 3655 times
Last updated: 8/30/16, 10:05 AM