跳至內容
選單
此問題已被標幟
7 回覆
33953 瀏覽次數

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.

作者

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.

作者 最佳答案

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>

頭像
捨棄

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.

最佳答案

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

頭像
捨棄
最佳答案

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>

頭像
捨棄
最佳答案

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

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
3月 24
4106
3
2月 18
7586
0
4月 23
3041
1
4月 20
6525
2
5月 19
6541