Search code examples
pythonodoo-12

How can I make a function that sends a custom email in odoo


Actually I have my custom template

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="as_email_template" model="mail.template">
            <field name="name">EMAIL TEMPLATE</field>
            <field name="model_id" ref="sale.model_sale_order"/>
            <field name="auto_delete" eval="True"/>
            <field name="email_from">${(object.res_user_id.email}</field>
            <field name="email_to">${object.client_name.email}</field>
            <!-- <field name="report_template" ref="action_example_pdf"/> -->
            <field name="subject">lolla</field>
            <field name="body_html">
                Hello this is a test from odoo
            </field>
        </record>
    </data>
</odoo>

And I want to send in a native function from odoo called action_confirm

@api.multi
def action_confirm(self):
    res= super(AsSaleOrder, self).action_confirm()
    return res

But I don't know how can I make a function that sends my custom email template.


Solution

  • You can use this structure to send the mail with custom template.

    template = self.env.ref('your_module_name.as_email_template', False)
    template.send_mail(self.id)