Search code examples
xmlodoo-8odooodoo-view

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


I want to add a button to a tree view and I want to make it invisible when the purchase_line_id is NULL.

How can I do that? Following is my view inherit code.

<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>

Solution

  • Try just

    <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)]}" />