-->

Odoo 10 - Conditional hide/show of kanban view ima

2019-08-19 10:52发布

问题:

I am trying to hide the product image based on the status of default_code field. If default_code is empty, I want to hide it. If not, I want to show image.

So far I have modified the kanban view like this:

<record id="conditional_product_kanban_view" model="ir.ui.view">
    <field name="name">Kanban Extended View</field>
    <field name="inherit_id" ref="product.product_template_kanban_view"/>
    <field name="model">product.template</field>
    <field name="arch" type="xml">
        <xpath expr="//div[@class='o_kanban_image']" position="replace">
            <div class="o_kanban_image">
                <img t-att-src="kanban_image('product.template', 'image_small', record.id.value)"/>
            </div>                
        </xpath>
    </field>
</record>

which basically does nothing.

What shall be added to <img> tag so image is displayed or hidden based on default_code field?

回答1:

you can put into condition like t-if

<t t-if="record.default_code.value>
 <div class="o_kanban_image">
            <img t-att-src="kanban_image('product.template', 'image_small', record.id.value)"/>
        </div>
</t>