使用 attrs 根据条件隐藏按钮

Hide button depending on condition with attrs

我想用属性隐藏一个按钮,但它不起作用。这是我的代码:

<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

它没有给出错误消息,但它无法正常工作。

"attrs" 和 "states" 不能在同一个按钮中。 从您的按钮中删除 "states" 并将其用作按钮功能的条件(在 python 文件中)。