Odoo Help


Qweb If statement if one is False show other if

Darius Martinkus
on 3/9/15, 5:26 AM 3,846 views

Hello Odoo community,

I have a if statement in the qweb, which when you rollover the object shows the message box which contains that product details, but if product ID is not found message wont be displayed which is correct, but how i can make another if statement saying "product not found" which would be shown only if first if statement is false?

Also i tried to put another if statement outside of <t t-foreach="docs" t-as="o"> tag which kind of worked on product ID which was not found i get the message but the message is displaying on the other products too, details + message ...

Code example

<div id="object">
        <div id="message">
        <t t-foreach="docs" t-as="o">
               <t t-if="o.id==3539">
                <p><strong>Contract Name: </strong><t t-esc="o.contract_name"/></p>
                <p><strong>Unit Name: </strong><t t-esc="o.unit_name"/></p>
                <p><strong>Unit Area: </strong><t t-esc="o.unit_area"/><t t-esc="o.unit_area_uom"/></p>
                <p><strong>Current Rent: £ </strong><t t-esc="o.contract_rent"/></p>
                <p><strong>Tenancy Status: </strong><t t-esc="o.tenancy_status"/></p>
<area shape="poly" coords="548,384,607,352,585,493,534,474" alt="TM-D-D-GF-D04" target="TM-D-D-GF-D04" t-att-href="'/web#id=%s&amp;view_type=form&amp;model=account.analytic.account&amp;menu_id=564&amp;action=692' % (o.url)"/>              

Any examples, suggestion and help would be appreciated

Thank you,




| 5 3 8
Pondicherry, India
On 3/9/15, 5:45 AM

Hi Darius,

The QWeb does not contains any structure for else.

So you can use the if - else condition like this:


          <t t-if="true == true"> true is true </t>

           <t t-if="true == false"> true is not true </t>



QWeb doesn’t have an “else” structure, use a second t-if with the original condition inverted. You may want to store the condition in a local variable if it’s a complex or expensive expression.


Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/24/15, 11:43 AM

Hi, qweb supports the conditional structure for if-else.

For eg:

CLient: <t t-esc="order.changed.client ? order.changed.client.name : 'Client anyone'"/> 

This works same as if-else condition.

You may also check this post:


Darius Martinkus
On 3/10/15, 12:04 PM

Nvm solved with extra function , thanks anyway

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/9/15, 5:26 AM
Seen: 3846 times
Last updated: 10/24/15, 11:46 AM