コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
8611 ビュー

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"/>
</tr>

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?

Regards

アバター
破棄

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

著作者 最善の回答

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?

著作者

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

著作者

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

最善の回答

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

アバター
破棄
最善の回答

Hello,

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

 

JKE

 

Duplicated:

https://www.odoo.com/forum/help-1/question/how-to-pass-qweb-variable-values-within-html-elements-in-a-loop-71675

https://www.odoo.com/forum/help-1/question/qweb-loop-cannot-set-value-to-vaiables-outside-the-loop-71486

https://www.odoo.com/forum/help-1/question/qweb-get-variable-value-from-loop-74531

https://github.com/odoo/odoo/issues/4461

アバター
破棄

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

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

関連投稿 返信 ビュー 活動
1
4月 25
1027
2
3月 25
1155
4
11月 24
6910
1
3月 24
1845
3
9月 23
24590