Odoo Help


Field access rights

Julius Petraška
on 8/13/15, 10:15 AM 1,381 views

I have a module with 3 fields:

  • name = fields.Char(...)

  • description = fields.Char(...)

  • forbridden_user = fields.Many2one('res.user',...)

When I create a record in field forbridden_user I select user which I want prevent from editing field description. How could I achieve that? I tried doing the fallowing:

  • <field name="description" attrs="{'readonly': [('forbidden_user', '=', 'uid')]}"/>

But it doesn't work. 

  • <field name="description" attrs="{'readonly': [('forbidden_user', '=', uid)]}"/>

Causes error:

  • Error details: "name 'uid' is not defined" while evaluating

Tarek Mohamed Ibrahim
On 8/13/15, 10:49 AM

First, you have to replace the uid by a function field that returns the current login id.

You have also to put "!=" instead of "="

so your line will be 

<field name="description" attrs="{'readonly': [('forbidden_user', '=', uid)]}"/>

But even if you did that, you won't be able to access the field 'description' in 'create' mode.


I think you have to create a group of the users that allowed to see this field, or the converse if you wish, and create a function field that returns true if the current user is in the specified group. Then based on this function field you can set the 'readonly' attribute

Pls check this link and the links similar it.

Note :

I used the uid in defining domain of an action in the xml file. I tried to put the uid in the attributes definition of a field in the xml in the view definition and I got the same error as yours, so I think you have to try the 2nd solution I posted.



Just make your field defination inside xml as like below.

<field name="description" attrs="{'readonly': [('forbidden_user', '=', uid)]}"/>

Here you need to write UID as variable not as text.

I hope it will resolve your issue.


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: 8/13/15, 10:15 AM
Seen: 1381 times
Last updated: 8/13/15, 11:53 AM