Odoo Help


hide fields based on curent user login

on 10/6/15, 5:35 PM 1,308 views


Sorry for my poor english i'm french ;-)

So.. I would like to hide fields based on curent user login.

I have some 10 employee and 10 users associate.

- i want that all users can see the 10 employee data but exept one (or more) field for exemple the field "phone"

- I want just the users login can modifiy is own employee data

I don't know how to do!!!

i try to put the condition this condition on the field but it doesn't work!

{'invisible': [('user_id','!=','user_id')]}

How can i give the user login and compare it to the related user of the employee?

i tried this but the result is : name 'uid' is not defined I'm on odoo 8, i think this work on openerp 6 but not now!!!!

on 10/6/15, 5:53 PM

I have a solution for you, let me write it

Axel Mendoza
on 10/6/15, 11:51 PM

see my updated answer

Axel Mendoza
on 10/7/15, 12:09 AM

The users can see all the fields of their own employee data? And they can see only limited fields of other employees, but can't modify. You need to have like this?

Akhil P Sivan
on 10/7/15, 12:33 AM


| 4 4 5
Hyderabad, India

On 10/7/15, 1:15 AM


You can do this by having a record rule for hr.employee object in which you can have domain like:

and remember to allow this rule for WRITE permission only(uncheck create/read/delete boxes)

and assign this to employee group.

Hope it helps!    

On 10/7/15, 4:00 AM

hello Axel

thank you, I think it's the good solution.

I try this, i create a new module but i have an error when i update my module list:

    'user_uid': fields.function(_get_uid, type='integer', string='User UID'),

    AttributeError: 'module' object has no attribute 'function'

Can you help me?

this is my hr_employee_cu.py

from openerp.osv import osv, fields

class HrEmployeeCu(osv.osv):

_inherit = 'hr.employee'

def _get_uid(self, cr, uid, ids, field_name, args, context=None):

return dict([(idx, uid) for idx in ids])

_columns = {

'user_uid': fields.function(_get_uid, type='integer', string='User UID'),


_defaults = {

'user_uid': lambda self, cr, uid, c: uid,


Hello Axel

Sorry but i don’t understand ?

What it fixed?

It's fixed in your own answer

Axel Mendoza
on 10/7/15, 11:18 AM

you have modify my code directly in my code? Sorry but i don't see the difference! It's late in france my eye nor really open ;-)

on 10/7/15, 5:20 PM

let me put the changes in bold

Axel Mendoza
on 10/8/15, 10:58 PM

OK now the module installing whitout error but my field 'user_uid' doesn't create in database! from openerp import models, fields class HrEmployeeCu(models.Model): _inherit = 'hr.employee' user_uid = fields.Integer(string='User UID', compute='_get_uid') def _get_uid(self, cr, uid, ids, field_name, args, context=None): return dict([(idx, uid) for idx in ids]) _defaults = { 'user_uid': lambda self, cr, uid, c: uid, }

on 10/13/15, 3:34 AM

Axel Mendoza

--Axel Mendoza--
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/6/15, 5:50 PM

You need to define a field function that return the uid of the user:

class test_x(osv.osv):
    _name = 'model_x'
    def _get_uid(self, cr, uid, ids, field_name, args, context=None):
        return dict([(idx, uid) for idx in ids])
    _columns = {
        'user_uid': fields.function(_get_uid, type='integer', string='User UID'),
    _defaults = {
        'user_uid': lambda self, cr, uid, c: uid,

Try like this:

<field name="user_uid" invisible="1"/>
<field name="field_x" attrs="{'invisible': [('user_id','!=',user_uid)]}"/>

Anass Ahmed
On 10/8/15, 11:00 PM

Best way is to use *Groups* for different users, then put on your field the following attribute (for example: Salesman group only sees this field): groups="sale.group_sale_salesman" You can refer to the *Security* documentation section to know how to create new group from *data.xml* and assign users to it.

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 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: 10/6/15, 5:35 PM
Seen: 1308 times
Last updated: 10/8/15, 11:00 PM