Skip to Content
Menu
This question has been flagged
3 Replies
3806 Views

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
0
Nov 23
7
0
Apr 24
1153
1
Jun 22
2444
1
May 22
2489
4
Dec 23
37179