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 is failed to render ? [SOLVED]

By
yopi
on 2/17/15, 1:17 AM 3,155 views

Hello,

I define new process that will send the email automatically without through the wizard. 

I create new template (adapt from existing one), but when i send it, i check the email and the email i got is not supposed to be, the email is weird.

from the server is trace the log, they look like this:

 MissingError: ('MissingError', 'One of the documents you are trying to access has been deleted, please try again after refreshing.')
2015-02-17 05:44:08,316 1100 ERROR tes06 openerp.addons.email_template.email_template: Failed to render template <Template memory:7f76f8117bd0> using values {'format_tz': <function <lambda> at 0x7f76e8b8bc08>, 'ctx': {'default_use_template': True, 'lang': None, 'default_composition_mode': 'comment', 'default_template_id': 31, 'default_res_id': 56, 'mark_so_as_sent': True, 'default_model': 'sale.order', 'tpl_partners_only': True}, 'user': res.users(1,), 'object': account.invoice(56,)}

the email i got, is like this:

Hello ${object.partner_id.name},

We want to say thank you for your trusted to us.

Here the information about your sale order,

  REFERENCES
  Invoice number: ${object.number}
  Invoice total: ${object.amount_total} ${object.currency_id.name}
  Invoice date: ${object.date_invoice}
% if object.origin:   Order reference: ${object.origin}
% endif % if object.user_id:   Your contact: ${object.user_id.name} % endif

 

here my code:

@api.one

def action_mail_send(self):

mail_compose = self.env['mail.compose.message']

# get the template

template_id = self.so_paid_email_template()

# modify the context

ctx = dict()

ctx.update({ 'default_model': 'sale.order', 'default_res_id': self.ids[0], 'default_use_template': bool(template_id), 'default_template_id': template_id.id, 'default_composition_mode': 'comment', 'mark_so_as_sent': True, })

# compose message

new_message = mail_compose.with_context(ctx).create({ 'partner_ids': self.partner_id.email, 'body': template_id.body_html, })

# send

new_message.send_mail()

return True

 

Thank You,

0
yopi
On 2/18/15, 4:36 AM

I think i solved it. :)

it's a simple solution, just load the email template and then sent it

example: 

template_id = self.env.ref('model.xml_id')

template_id.send_mail(self.ids[0], force_send=True)

 

0
krishnakanth
On 3/16/16, 5:23 AM

Hi, Try this solution once as follows: If your rendering datetime field value: here object.cutoff_date is datetime field ${format_tz(object.cutoff_date, format= '%d/%b/%Y')} If Date field as follows: here object.cutoff_date is date field ${format_tz(object.cutoff_date+ ' 00:00:00', format= '%d/%b/%Y')}

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: 2/17/15, 1:17 AM
Seen: 3155 times
Last updated: 3/16/16, 5:23 AM