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

Hello,


I wish to compare a user id presente in my module with the id of the current user to make a button invisible or not, to do so i have a field with a user_id in it, in the Python:




And in the XML, the button look something like this:


In wish case i got the error:




i don't understand the error and i've tried a lot of "solution" that weren't solution to me. 


Thanks you for your future help,


Have a nice day.



Ewen JEZEQUEL

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

Hi,

UID usage in attrs is unsupported. Instead, employ a computed field for dynamic user ID comparison

current_user_id = fields.Many2one('res.users', compute='_compute_current_user_id', store=True)

def _compute_current_user_id(self):

    for record in self:

        record.current_user_id = self.env.user

<field name="intervenant_id" attrs="{'invisible': [('intervenant_id', '!=', current_user_id)]}"/>

Utilize this computed field in the XML view's attrs attribute to make the button invisible based on the current user ID.

<field name="intervenant_id" attrs="{'invisible': [('intervenant_id', '!=', current_user_id)]}"/>


This dynamic solution ensures invisibility for users whose intervenant_id doesn't match the current user ID. 


Hope it helps

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

Hi,


I've successfully implemented this issue by using the following code format:


attrs="{'invisible' : "[('intervenant_user_id', '=', uid)]"}"


You need to add " on both sides of the domain.

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

unfortunately, you can't do that comparison with uid in attrs

you can do the workaround by using the help of a new field that will always provide the current user id, like using compute or tampering with the form view nodes

references:
1. https://www.odoo.com/id_ID/forum/help-1/how-to-get-current-user-in-attrs-161197
2. https://www.odoo.com/id_ID/forum/help-1/attrs-of-field-in-xml-user-id-120897
3. https://www.odoo.com/id_ID/forum/help-1/how-get-current-user-id-in-xml-8521

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 11 23
7
0
thg 4 24
1225
1
thg 6 22
2483
1
thg 5 22
2582
4
thg 12 23
37298