如何在某些情况下在 Odoo 视图中使按钮不可见?

How to make a button invisible under some conditions on an Odoo view?

我想在树视图中添加一个按钮,并且我想在 purchase_line_id 为 NULL 时使其不可见。

我该怎么做?以下是我的视图继承代码。

<record id="view_move_pickingextended_tree" model="ir.ui.view">
            <field name="name">stock.move.tree.extended</field>
            <field name="model">stock.move</field>
            <field name="inherit_id" ref="stock.view_move_picking_tree"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='state']" position="after">
                    <button name="%(uom_conv_trans_level_thura)d" string="Manual Pick"
                            type="action" class="oe_highlight" icon="fa-book"
                            context="{'product_id':product_id}" invisible="context.get('purchase_line_id',False)"/>
            </xpath>
        </field>
    </record>

试试

<button name="%(uom_conv_trans_level_thura)d" string="Manual Pick"
        type="action" class="oe_highlight" icon="fa-book"
        context="{'product_id':product_id}"
        attrs="{'invisible': [('purchase_line_id', '=', False)]}" />