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 set field readonly for user

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

HI,

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

 

 

2

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
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

Thanks

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

René Schuster

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

Challenge Everything!

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

*EDITED*

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

.py:

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?'

.xml:

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

 

Regards.

@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
1

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 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

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

1 follower(s)

Stats

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