Search code examples
odooodoo-8odoo-12

Odoo 12 How to use render_qweb_html?


Hi I'm trying to create html from template in Odoo 12. I know from previous Odoo 8 we can use

html = self.env['report'].get_html(self, 'my_addon.my_template')

get_html method is no longer supported in Odoo 12. I read it was replaced by render_qweb_html

But when I tried like this

html = self.env['ir.actions.report'].render_qweb_html(self, 'my_addon.my_template')

Odoo respond with

AttributeError: 'str' object has no attribute 'setdefault'

Am I using the method incorrectly? Can anyone point where I made the mistake? I have looked for samples in the addons folder, yet found none.

Thanks


Solution

  • You can user templates render method.

    self.env.ref('template_external_id').render(render_context)
    

    For more information, you can follow the official documentation of qweb.