Odoo Help


QWeb loop cannot set value to vaiables outside the loop

Martin Pishpecki
on 12/24/14, 8:27 AM 2,986 views

Hello. I have foud this example on the forum:

<t t-set="i" t-value="1"/>
<tr t-foreach="o.order_line" t-as="l">
                        <td> <span t-esc="i"/> </td>
    <t t-set="i" t-value="i+1"/>

Any value to a variable set inside the loop, exsists only as loong as the loop exsists. If you try: <span t-esc="i"/> after the loop, you will see that the value is again 1.  You cannot set the value of variable declaired outside the loop. Where should this bug be reported?


Did you find a way around this? I am suffering the same issue.

Abdullah Sofan
on 12/28/14, 9:30 AM

Anyone can help on this?

Abdullah Sofan
on 12/29/14, 1:29 AM

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--

| 3 3 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 1/30/15, 9:02 AM


A discussion exits on github, you can check here https://github.com/odoo/odoo/issues/4461#issuecomment-72199618 the explication of Odony to know how to do it easily...

The propagation has been added since commit 4a698da (https://github.com/odoo/odoo/commit/4a698da) but in most case it should not be used to make sum, ... Qweb is for templating... 


Have a good day









Jérémy you are too fast for me today. Thanks for posting!

Stephen Mack
on 1/30/15, 9:06 AM

You too :) For Q74531 Thanks for your work on this forum !

Jérémy Kersten (jke)
on 1/30/15, 9:08 AM
Abdullah Sofan
On 12/29/14, 11:47 AM

Thanks for that. But this bug seems to defeat a major purpose of the loop function in Qweb.

Martin Pishpecki
On 12/29/14, 3:08 AM

Ok foud a workaround.

In my case I wanted to check if one ore more products belongs to a group. If the condiditon was true a div containig table and data is visible, if not its hidden. So I made something like this:

<div t-if=" True in [z.product_id.categ_id.name == 'WiMax' for z in o.order_line]" >...(your content goes here ).</div>

You can make inline labda function to loop over "o.order_line" and chek if "o.order_line.product_id.categ_id.name" (this is the category name) of each line is the category name you are looking for. This will result in list ex. [False, False, False, False, True]. So "True in [...]" evaluates if there is True in the list.  Hope you can use the same logic in your problem.

Thanks for that. Have you reported this bug?

Abdullah Sofan
on 12/29/14, 11:45 AM

No problem. I have not reported the bug. Where do I report this?

Martin Pishpecki
on 12/30/14, 2:25 AM

Ok. Reported on https://github.com/odoo/odoo/issues?q=is%3Aopen+is%3Aissue. If that is the right place. Regards.

Martin Pishpecki
on 12/30/14, 2:44 AM

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

3 follower(s)


Asked: 12/24/14, 8:27 AM
Seen: 2986 times
Last updated: 9/14/17, 5:43 AM