Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
4586 Ansichten

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

Avatar
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
Beste Antwort

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.

Avatar
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Nov. 23
7
0
Apr. 24
1639
1
Juni 22
2966
1
Mai 22
3014
4
Dez. 23
38244