Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
10070 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
paź 19
5903
0
sie 23
8
2
lis 22
3270
2
kwi 20
5661
1
lut 16
3444