Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
3921 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
nov. 23
7
0
apr. 24
1251
1
iun. 22
2548
1
mai 22
2618
4
dec. 23
37371