Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
10339 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 19
6235
0
thg 8 23
8
2
thg 11 22
3721
2
thg 4 20
5906
1
thg 2 16
3719