Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
14951 Weergaven

i have the following button in my form:

xml
<button name="button_approve" string="Approve order" attrs="{'invisible':['|', ('manager_id', '=','current_user'),('state' , 'not in', ['to approve'])]}
 <field name="dept_manager_id"/>
 <field name="current_user"/>

python
manager_id = fields.Many2one('res.users'
current_user = fields.Many2one('res.users', compute='_get_current_user')
    @api.depends()
    def _get_current_user(self):
        for rec in self:
            rec.current_user = self.env.user
        self.write({'current_user': self.env.user.id})
The attrs is designed to show the button only for orders if 'current_user' = 'manager_id' , with a status of 'to approve', however only the second part of the condition (status of 'to approve') was being evaluated correctly.

Avatar
Annuleer
Beste antwoord

Hi Saud, 

Seems like you wanted to hide button for current user which same as manager, or, state is 'to approve'.
try with : attrs="{'invisible':['|', ('manager_id.id', '=',user.id),('state' , 'not in', ['to approve'])]}
Also no need to store current user to field current_user.

Avatar
Annuleer

As far as my understanding, user.id will work only with the domain, not with attrs

Indeed @Niyas, that is why in my suggestion, i added a compute field for that.

Beste antwoord

Hi, 
Please follow instructions i gave in this link : https://www.odoo.com/fr_FR/forum/aide-1/question/maintenance-request-read-only-view-136023#answer-136027

Notes:

1-Since your case is about 'invisible', you can name your variable field_invisible.

2- you need to get the group your manager belongs to and add it in the section has_group.

3- in your field, you add attrs={'invisible':['|', ('field_invisible', '=', True), ('state' , 'not in', ['to approve'])]} and the boolean should be declared in your form with invisible="1".

Upvote if this helps. 

Thank you.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
jun. 19
15895
3
mei 16
3812
1
sep. 15
5468
1
mrt. 15
4683
2
mei 24
7580