Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Odoo16 qweb – convert float to int / loop through float

Good morning, in odoo 16 I created a view for printing product labels. Now I’m trying to make the number of labels match the amount of on hand. I’m using foreach, but the on hand value is float and foreach throws an error.

TypeError: 'float' object is not iterable

How do I convert float to int in qweb?
I tried to use range(qty) in foreach, but it doesn’t help

<t t-name="xxNAMExx">
  <t t-set="qty" t-value="product.qty_available"/> //float -> int??
  <t t-foreach="qty" t-as="item"> //<t t-foreach="range(qty)" t-as="item"> 
    <div>CONTENT</div>
  </t>
</t>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should convert the qty_available float-value to integer using int():

<t t-name="xxNAMExx">
  <t t-set="qty" t-value="int(product.qty_available)"/>
  <t t-foreach="range(qty)" t-as="item">
    <div>CONTENT</div>
  </t>
</t>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading