Search code examples
odoo-15

Odoo pdf report, how to show foreach loop index


How can I show the index number of t-foreach look? I want to show index of each line in the pdf report

<t t-set="lines" t-value="delivery.mapped('delivery_line_ids')"/>
   <tr t-foreach="lines" t-as="line">
      <span t-field="???????"/> 
   </tr>
</t>

Solution

  • In addition to the name passed via t-as, foreach provides a few other variables for various data points listed in the Odoo qweb templates loops section.

    You can access the current iteration index using $line_index variable (the first item of the iteration has index 0)