Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
10055 Vistas

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

Avatar
Descartar
Mejor respuesta

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.

Avatar
Descartar
Mejor respuesta

Hi,

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.

Thanks.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
oct 19
5883
0
ago 23
8
2
nov 22
3229
2
abr 20
5643
1
feb 16
3409