Odoo Help

Welcome!

This community 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.

1

Qweb If statement if one is False show other if

By
DM
on 3/9/15, 5:26 AM 2,337 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,

5

Vasanth

--Vasanth--
3458
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
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:

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

1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
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:

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

1
DM
On 3/10/15, 12:04 PM

Nvm solved with extra function , thanks anyway

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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