Reputation: 111
I am trying to send an email from a custom module but an error like this occured: "Failed to render template"
I actually received an email but the body of content was not the same. Here's the code in XML file:
<odoo>
<data noupdate="1">
<record id="task_email_template_one" model="mail.template">
<field name="name">Task Email</field>
<field name="email_from">${object.user_email| safe}</field>
<field name="email_to">${object.user_id}</field>
<field name="subject">The Task ${object.name}</field>
<field name="lang">${object.lang}</field>
<field name="model_id" ref="task.model_project_task"/>
<field name="body_html"><![CDATA[
<p>
Sample Message
</p>
]]>
</field>
</record>
</data>
It seems that the template being used was from mail_template.xml
<template id="message_user_assigned">
<p>Dear <t t-esc="object.user_id.sudo().name"/>,</p>
<p>You have been assigned to the <t t-esc="object._description.lower()"/> <t t-esc="object.name_get()[0][1]"/>.</p>
<p>
<a t-att-href="'/mail/view?model=%s&res_id=%s' % (object._name, object.id)"
style="background-color: #9E588B; margin-top: 10px; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 16px;">
View <t t-esc="object._description.lower()"/>
</a>
</p>
<p style="color:#9E588B;">Powered by <a href="https://www.odoo.com">Odoo</a>.</p>
</template>
The custom email template wasn't used instead it uses the ones from mail_template, how can I possibly resolve this?
Edited: I made some changes from my XML file, there were no errors but still the email's body content wasn't the same
Upvotes: 1
Views: 667
Reputation: 16743
There are multiple mistakes,
email_from
there is a typo. Instead of ${object.user.id.email| safe}
it can be ${object.user_id.email| safe}
project.model_project_task
) not task.model_project_task
email
of the user in the email_to
Check below the improved mail template.
<data>
<record id="task_email_template_one" model="mail.template">
<field name="name">Task Email</field>
<field name="email_from">${object.user_id.email| safe}</field>
<field name="email_to">${object.user_id.email}</field>
<field name="subject">The Task ${object.name}</field>
<field name="lang">${object.lang}</field>
<field name="model_id" ref="project.model_project_task"/>
<field name="body_html"><![CDATA[
<p>
Sample Message
</p>
]]>
</field>
</record>
</data>
Because you added the noupdate=1
, delete the mail template, and upgrade the module again in order to apply the changes, you should remove the noupdate=1
when you are developing the module :)
Upvotes: 2