Skip to Content
Menu
This question has been flagged
4 Replies
30173 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,

Avatar
Discard
Author Best Answer

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)

 

Avatar
Discard

This is working good

Best Answer

Salut!! Je suis en train de créer un devis mais à chaque fois qu'il faut valider mon devis, Odoo m'envoit un message en disant que la ligne n'est pas défini. Alors je ne sais pas comment faire!

L'erreur en question :  Failed to render template : 'line' is undefined

Avatar
Discard
Best Answer

Hi ,Create a new custom module and write the same code. It works.

Avatar
Discard
Best Answer

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')}

Avatar
Discard
Related Posts Replies Views Activity
3
Apr 22
10437
4
Nov 19
11630
0
Nov 18
3460
3
Jan 18
7591
1
Sep 16
3075