콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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
3051
3
2월 18
7150
0
4월 23
2414
1
4월 20
5849
2
5월 19
5966