Odoo 15 _render_template problem ?

Returning {1: Markup('') } instead of the rendered template

vITraining Admin

In Odoo 15, mail.template function _render_template seems different with older versions

When we execute this code:

self.body_surat = self.template_mail_id._render_template(
self.template_mail_id.body_html,
'vit.surat',
self.ids,
engine="qweb"
)

we got this result:




How to fix it?


Apparently, _render_template now returns a dictionary with key of model id and value of the rendered template, as with the res_ids parameter as well now requires a list of ids of the model to be rendered.

Here is the solution..


self.body_surat = self.template_mail_id._render_template(
self.template_mail_id.body_html,
'vit.surat',
self.ids,
engine="qweb"
)[self._origin.id]


We take the dictionary value of the _render_template return value, by assigning the current document id as the key.

Why self._origin.id ?

This is because the sample code resides on an onchange function.

If it is on a regular function, then just use [self.id]