Today we are going to discuss, how to use/change the context in dynamic/custom templates.
Let's say we want to send some values to an email template other than normal object id, here is the code for that
In controllers/main.py
local_context = request.env.context.copy()
In module.py file
local_context = self.env.context.copy()
local_context.update({
'name': 'Shiv',
'place': 'Bangalore'
})
template = request.env.ref('module_name.email_template_id')
template.with_context(local_context).send_mail(object.id, force_send=True, raise_exception=True)
In email template code you can access context as:
<p>${ctx['name']}</p>
<p>${ctx['place']}</p>
That's it.
To know how to create a custom email template, please check here: http://www.odoo.yenthevg.com/creating-mail-templates/
Thanks!!! Enjoy Programming!!! :)
Thank you. This tip helped me today after I'd spent about 2 days trying to send an email.
ReplyDeleteHappy to hear that, at-least this post helped someone :)
Deletegreat article :) you save my day today.... thumbs up
ReplyDeleteGood to hear that...
DeleteGood stuff, I asked my team to refer this!!
ReplyDeletenice
ReplyDeleteCan we send multiple email id in email_to field like this method.
ReplyDelete