Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Email template with for-loop

By
Seppe De Roeck
on 5/14/15, 5:03 AM 2,749 views

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

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.

Shawn Varghese
on 5/14/15, 7:22 AM

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.

Seppe De Roeck
on 5/14/15, 8:26 AM
0
Pambudi Satria
On 8/3/16, 9:46 PM

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

0
Seppe De Roeck
On 5/14/15, 5:52 AM

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>

0
Deviprasad V
On 5/14/15, 5:23 AM

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>

0
Deviprasad V
On 5/14/15, 5:23 AM

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>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/14/15, 5:03 AM
Seen: 2749 times
Last updated: 8/3/16, 9:47 PM