Skip to Content
Odoo Menu
  • Sign in
  • 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
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Email template with for-loop

Subscribe

Get notified when there's activity on this post

This question has been flagged
translationstemplatesmakoemailtemplate
7 Replies
34993 Views
Avatar
Seppe De Roeck

Hi all,

I am trying to create an email template that makes a small html table per record type, then creates a line for every record.

The current draft code is below.  However, the email template doesn't show anything, not even the first html line.

Does anybody know why Odoo is not rendering or at least trying to render this block ?  It seems the templates are hard to control as sometimes the code in translations is taken outside the for-block.  But even when the code stays like the below nothing is rendered.


<b>Here is your overview</b><br><br>

${prevtype} = ''

% for aline in object.x_alert_line_ids:

      % if ${aline.x_alert_type} != ${prevtype} :

            % if ${prevtype} != '' :

                  </tbody></table><br><br>

             %endif

             <b>NEXT TYPE</b><br>

             <table border="1"><tbody>

      % endif

      <tr>

      <td>${aline.x_CPO}</td>

      <td>${aline.x_customer}</td>

      <td> ${aline.x_factory} </td>

      <td> ${aline.x_effective_ready_date} </td>

      </tr>

      ${prevtype} = ${aline.x_alert_type}

% endfor

0
Avatar
Discard
Shawn Varghese

Seppe, just to confirm, you are using the Preview button to view the template right? Because the for loop only executes and renders when it is run or when you press Preview. Might be a silly question, but it seemed to me like you were only viewing the static content.

Seppe De Roeck
Author

Hi Shawn, yes I am watching it in the preview mode or executing the server action that really sends the email. I get an empty email body and mostly the email template's code inside the for loop is changed automatically and put outside the loop for example. Seems the templates are buggy or some code is not really liked and then it behaves very strange.

Avatar
Seppe De Roeck
Author Best Answer

Hi Deviprasad,,

That's a good example of what is going wrong.  I copy/paste your code in the template, save it and edit it again.

This is the code that pops out : as you see below the whole block has been moved outside the for loop.



% for row in object.move_lines:

%endfor

<table>

<tbody>

<tr>

<th style="width:135px">Product description</th>

<th style="width: 85px;">Qty Shipped

</th><th style="width: 125px;">Date Shipped</th>

</tr><tr>

<td> ${row.name}</td>

<td style="text-align: center;">${row.product_qty or ''}</td>

<td>${object.date_done or ''}</td>

</tr></tbody><tbody>

</tbody></table><table>

</table>

1
Avatar
Discard
Andre Bal

This problem still exists in 2021. The Odoo editor knows better and changes the code on saving... Is there any way around this? Because makeup in tables makes aligning information a lot prettier.

Avatar
Pambudi Satria
Best Answer

It's an issue, you can see it here: https://github.com/odoo/odoo/issues/2166

1
Avatar
Discard
Avatar
Deviprasad V
Best Answer

use this 

<table>

<tbody>

<tr>

<th style="width:135px">Product description</th>

<th style="width: 85px;">Qty Shipped</td>

<th style="width: 125px;">Date Shipped</th>

</tr>

% for row in object.move_lines:

<tr>

<td> ${row.name}</td>

<td style="text-align: center;">${row.product_qty or ''}</td>

<td>${object.date_done or ''}</td>

</tr>

%endfor

<tbody>

<table>

1
Avatar
Discard
Avatar
Deviprasad V
Best Answer

\use this 

<table>

<tbody>

<tr>

<th style="width:135px">Product description</th>

<th style="width: 85px;">Qty Shipped</td>

<th style="width: 125px;">Date Shipped</th>

</tr>

% for row in object.move_lines:

<tr>

<td> ${row.name}</td>

<td style="text-align: center;">${row.product_qty or ''}</td>

<td>${object.date_done or ''}</td>

</tr>

%endfor

<tbody>

<table>

1
Avatar
Discard
Avatar
Eman Abdulmalik
Best Answer

Use the following to loop through objects. Lets say the field you want to loop is called "lines":

The below will loop through all the field lines and output the value of the name field.


% for row in object.lines:

            <td> Deposit : ${row.name}</td>

            % endfor

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Change default recipient for Invoice: Sending email template Solved
templates invoces emailtemplate
Avatar
Avatar
Avatar
3
Mar 24
5597
XML Template Email
email templates emailtemplate
Avatar
Avatar
3
Feb 18
8221
Email Marketing and Marketing Automation Templates not rendering properly
templates nginx emailtemplate v15
Avatar
0
Apr 23
3834
Odoo13 External ID not found in the system: account.model_account_invoice Solved
templates emailtemplate odoo12 Odoo13.0
Avatar
Avatar
1
Apr 20
7447
Odoo 12, Error with translation on email templates
templates emailing emailtemplate Odoo12.0
Avatar
Avatar
Avatar
2
May 19
7239
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