Skip to Content
Menu
This question has been flagged
2 Replies
2757 Views

Hello,

I am trying to make appear a smart button when a user of the "leader group" is looking the view. I write this function:

    @api.depends('state')
    def _compute_can_leader_approved(self):
        user = self.env['res.users'].browse(self.env.uid)   
        if(self.state == 'to_approve' and user.has_group('sprogroup_purchase_request.group_sprogroup_purchase_request_leader')):
            self.can_leader_approved = True
        else:
            self.can_leader_approved = False
    can_leader_approved = fields.Boolean(string='Can Leader approved',compute='_compute_can_leader_approved' )
                      

  <button name="button_leader_approved"
                                string="Leader Approve"
                                type="object"
                                class="oe_highlight"
                                groups="sprogroup_purchase_request.group_sprogroup_purchase_request_leader"
                                attrs="{'invisible': [('can_leader_approved', '=', False)]}"/>
But when I am logged as "leader" the button doesn't appear because the flag of can_leader_approve still be False.Can you hel me?
Avatar
Discard

To customize modules, just go through these tips: https://github.com/sehrishnaz/learnopenerp/wiki

Best Answer

Probably your problem is related to multi recordset, try this:

    @api.depends('state')
    def _compute_can_leader_approved(self):
        user = self.env.user
        for rec in self:  
            if (rec.state == 'to_approve' and user.has_group('sprogroup_purchase_request.group_sprogroup_purchase_request_leader')):
                rec.can_leader_approved = True
            else:
                rec.can_leader_approved = False

Avatar
Discard
Related Posts Replies Views Activity
4
May 24
10062
1
Apr 24
1560
0
Nov 23
522
1
Sep 23
559
2
Aug 23
2420