简体   繁体   中英

Odoo Email template render error

I'm sending email from module @override create method here is my method

@api.model
def create(self, values):
    res = super(licenses, self).create(values)
    template = self.env.ref('licenses.license_create_email_template', False)
    # Send out the e-mail template to the user
    self.env['mail.template'].browse(template.id).send_mail(res, force_send=True)
    return res

here is my template

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data noupdate="1">
        <record id="license_create_email_template" model="mail.template">
            <field name="name">License Create</field>
            <field name="email_from">${user.email|safe}</field>
            <field name="subject">License Create</field>
            <field name="email_to">${object.x_partner_id.email}</field>
            <field name="model_id" ref="licenses.model_licenses_licenses"/>
            <field name="auto_delete" eval="True"/>
            <field name="lang">${object.x_partner_id.lang}</field>
            <field name="body_html"><![CDATA[
             The License of ${object.x_partner_id.name} has been created.
        ]]></field>
       </record>
    </data>
</odoo>

When i preview template from setting it rendering correctly but when i render email template from code it gives render error here is render error picture (Picture)Email template render problem error

One of the parameters for send_mail method of mail.template model is res_id that is an integer, take a look its definition . And if you are using .v10 new api, acording to the documentation create method returns a recordset not an integer, therefore you sould get the id from that record set in this way res.id and pass it as a parameter of send_mail .

I hope this answer can be helpful for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM