Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a "for-loop" with a specific number of loops in Qweb?

I would like to make a loop to print elements an exact amount of times. Something like this:

<t t-for="o.label_qty" >
...
</t>

Where o.label_qty is an integer number.

But I can use only a t-foreach loop in qweb:

<t t-foreach="o.pack_operation_ids" t-as="l" >
...
</t>

Is there a way to do this?

If not I'm thinking the only solution is to create a dummy list with o.label_qty elements and write it in the foreach.

like image 528
ChesuCR Avatar asked Jul 17 '15 12:07

ChesuCR


2 Answers

The t-foreach directive accepts a Python expression. So, you could use range() just like in Python for loops:

<t t-foreach="range(o.label_qty)" t-as="l">
...
</t>
like image 75
Daniel Reis Avatar answered Sep 27 '22 18:09

Daniel Reis


yes it totally possible in Odoo Qweb Report you just need to add the below way to do somethings like this

     <t t-foreach="o.pack_operation_ids" t-as="l" >
         <td class="col-xs-1">
             <span t-esc="l_index+1"/>
         </td>
     </t>

hear the <span> tag is print the total no of times loop will be executed while we are printing our qweb report. index is the part of Qweb Template Engine so hear it is always start with 0 element.

I hope my answer may help you :)

like image 34
DASADIYA CHAITANYA Avatar answered Sep 27 '22 20:09

DASADIYA CHAITANYA