Amy
Amy

Reputation: 70

Hide button depending on condition with attrs

I m trying to hide a button with attrs but it's not working. Here is my code:

<button name="button_to_approve" states="draft"
                        string="Request approval" type="object"
                        class="oe_highlight"                            
                        groups="mygoups"
                        attrs="{'invisible': [('is_responsible', '=', False)]}">
                          <field name="is_responsible" invisible="1"/>    
                </button>

Python code :

is_responsible = fields.Boolean('Is current user', compute='_compute_is_member')

@api.multi
def _compute_is_member(self):
    self.ensure_one
    if self.env.uid == self.assigned_to_responsible_affected_to.id:
        self.is_responsible = True
    else:
        self.is_responsible = False

It's not giving an error message but it's not working correctly.

Upvotes: 1

Views: 696

Answers (1)

Oumaima Abouzaid
Oumaima Abouzaid

Reputation: 96

"attrs" and "states" must not be in the same button. remove "states" from your button and use it as a condition in the function of your button (in the python file).

Upvotes: 2

Related Questions