Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How do you use variables in a Qweb loop?

Naroči se

Get notified when there's activity on this post

This question has been flagged
v8qwebreportloop
11 Odgovori
94483 Prikazi
Avatar
Jeff Beidler

This page of the documentation describes variables that can be used in a t-foreach loop in Qweb, but doesn't provide any examples of how to access those variables.  I was thinking that I could use the $as_index variable to list line numbers on a sales order, but everything I have tried causes an error.  Can anyone provide an example of how to output the index?  Or, even better, the index + 1, since it starts at zero?

2
Avatar
Opusti
Sehrish

look into: https://learnopenerp.blogspot.com/2020/08/create-custom-report-in-odoo-using-qweb.html

Avatar
Sajin Aziz
Best Answer

try this code inside table,

 <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>

18
Avatar
Opusti
Jeff Beidler
Avtor

That's what I came up with, too. Just wanted to know how to do it in the manner described in the "documentation".

iWesabe Technologies

+1

Avatar
Jeff Beidler
Avtor Best Answer

I got the $as_index variable to work.  Here is an example:

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

The index is zero-based, hence the addition of 1.  Hope this helps.

7
Avatar
Opusti
Avatar
Ajepe Babatope
Best Answer

This is pretty simple and straight forward.

When we define our loop like this:

<code>

<t t-foreach="people" t-as="person">

<tr>

<th scope="row"><span t-raw="person_index"/></th>

<td><span t-field="person.name"/></td>

<td><span t-field="person.age"/></td>

<td><span t-raw="person.weight"/></td>

</tr>

</t>

</code>

To get the current index/position of the person with the loop you can do person_index. i.e your variable_index or any other available variable withing the context of qweb loop.

3
Avatar
Opusti
Avatar
Martin Pishpecki
Best Answer

I have tryed this:

<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>

When the loop finishes, the ounter resets to 1. Does anyone kow a way to update a variable outside the loop? I would like to define a variable before the loop and set it to false. If I find what I am looking for inside the loop I would like to set the value of the variable to True. This var would later be used as a condition if a div is visible or not.

Any help is appreciated. Thx

0
Avatar
Opusti
Avatar
Antony Lesuisse (al)
Best Answer

var_index is automatically defined

Check https://www.odoo.com/documentation/8.0/reference/qweb.html#loops

0
Avatar
Opusti
Jeff Beidler
Avtor

Yes, that is the page I linked in my question. What I was hoping for was an example of usage. Everything I tried resulted in an error.

Luke Branch

@Antony Lesuisse, Thanks for the link. I'm currently building a community module to add multiple product images for use in the website e-commerce pages here: https://github.com/OdooCommunityWidgets/website_multi_image unfortunately i've only just begun playing around with Odoo development and I have hit a brick wall trying to figure out how to create a t-foreach loop to output all images in the one2many in this module. Do you have any suggestions on how I could achieve this in 8.0?

OdooBot
https://www.odoo.com/documentation/8.0/reference/qweb.html

Use the doc Luke ! :)

On 12/04/2014 12:16 PM, Luke wrote:
> @Antony Lesuisse, Thanks for the link. I'm currently building a community
> module to add multiple product images for use in the website e-commerce pages
> here: https://github.com/OdooCommunityWidgets/website_multi_image
> unfortunately i've only just begun playing around with Odoo development and I
> have hit a brick wall trying to figure out how to create a t-foreach loop to
> output all images in the one2many in this module. Do you have any suggestions
> on how I could achieve this in 8.0?
>
> --
> Luke
> Sent by Odoo S.A.  using Odoo 
> about Forum Post False 
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Create QWeb reports from Odoo application
v8 qweb report
Avatar
0
dec. 15
5095
Edit the qweb template with a custom modul. Solved
v8 qweb report
Avatar
Avatar
Avatar
3
mar. 15
18827
Transfer the sum of all order lines of one page to the next page.
v8 qweb report
Avatar
0
mar. 15
3934
Set report orientation Solved
v8 qweb report
Avatar
Avatar
1
mar. 15
15040
Inherit Qweb Solved
v8 qweb inherit report
Avatar
Avatar
Avatar
Avatar
4
feb. 24
49673
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now