Skip to Content
Menu
This question has been flagged

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

Avatar
Discard

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.

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.

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>

Avatar
Discard

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.

Best Answer

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

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

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

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

Avatar
Discard
Related Posts Replies Views Activity
3
Mar 24
1395
3
Feb 18
6558
0
Apr 23
1841
1
Apr 20
5220
2
May 19
5400