Odoo Help


How to set field readonly for user

Jagdish Panchal
on 7/23/14, 5:14 AM 1,632 views


I have 3 field in my view

                                <field name="name" />
                                <field name="date" />
                                <field name="nbc" />

I want set name and date field read only for hr_manager. how can i ?

Any help ??






| 5 5 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 7/23/14, 7:16 AM

Create function field that returns a value based on the user's group and then use attrs attributes on fields to control.

Reference :https://answers.launchpad.net/openobject-server/+question/178779


Jagdish Panchal
on 7/24/14, 2:02 AM

René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 7/23/14, 6:33 AM


One solution is to combine a function field with the attrs tag:


def _get_uid_is_manager(self, cr, uid, ids, field_name, arg, context=None):
        res = {};
        manager_group_id = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'group_hr_manager').id
        manager_ids = self.pool.get('res.user').search('groups_id', '=', manager_group_id);
        for obj in self.browse(cr, uid, ids, context=context):
            res[obj.id] = uid in manager_ids;
        return res;

'uid_is_manager': fields_function(_get_uid_is_manager, type='boolean', method=True, string='Current User is Manager?'


<field name="name" attrs="{'readonly': [('uid_is_manager' ,'=', True)]}"/>
<field name="date" attrs="{'readonly': [('uid_is_manager' ,'=', True)]}"/>



@René Schuster: Thanks for the answer, I want make read only dont want hide.By using this code its hide for other user.

Jagdish Panchal
on 7/23/14, 6:50 AM

Sorry, got you wrong. I've edited my answer (but was slower than prakash ^^).

René Schuster
on 7/23/14, 7:25 AM

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 7/23/14, 5:21 AM

Hi, you can use this as example...

'name': fields.char('Name', size=128, read=['base.group_userA'], write=['base.group_userB'] )

Read will allow the user group to view and Write will allow the user group to edit the field..

I have try this but its not working

Jagdish Panchal
on 7/23/14, 5:37 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

1 follower(s)


Asked: 7/23/14, 5:14 AM
Seen: 1632 times
Last updated: 3/16/15, 8:10 AM