Skip to Content
Menu
This question has been flagged
3 Replies
20958 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)"/>              
   </t>
    </t>     
</div>       
    </div>

Any examples, suggestion and help would be appreciated

Thank you,

Avatar
Discard
Best Answer

Hi Darius,

The QWeb does not contains any structure for else.

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

<div>

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

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

</div>

Note

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.

Avatar
Discard
Best Answer

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:

https://www.odoo.com/forum/help-1/question/how-to-check-if-client-is-selected-in-pos-ticket-91970 

Avatar
Discard
Author Best Answer

Nvm solved with extra function , thanks anyway

Avatar
Discard