Skip to Content
Menu
This question has been flagged
2 Replies
3538 Views

How can I add the company logo to an email template? I want it to automatically change every time the company logo is changed in the template... I have tried several options, but the only code that works for me is working is this:

                                                       

                                                             style="padding: 0px; margin: 0px; height: auto; width: 80px;"

                                                             alt="${object.company_id.name}"/>

                                                   

this defaults to an odoo logo, but I want the one I have added to the company (I am using multi-company)

odoo 15 community, thank you.

Avatar
Discard
Best Answer

Hi,


You can try to use these codes in your templates

<p> <img src="data:image/png;base64,${object.company_id.logo}" /> </p>


Gmail, and probably many other emails, do NOT support base64 images, you have to use a URL, like:

https://your-website.com/web/image/res.company/${object.company_id.id}/logo?width=180" alt="${object.company_id.name}"/>



Regards

Avatar
Discard
Best Answer

You have to update/inherit all mail templates that are required (Settings > Companies > Email Templates > Review All Templates). In addition, Odoo uses two base templates (mail.mail_notification_layout and mail.mail_notification_light in the mail_templates.xml from the mail module). Update/inherit these as well. E.g.,


Regarding the changes. You should replace the following:

<img t-att-src="'/logo.png?company=%s' % (company.id or 0)" style="padding: 0px; margin: 0px; height: auto; max-width: 200px; max-height: 36px;" t-att-alt="'%s' % company.name"/>

With this:

<t t-if="company.logo">
    <img t-att-src="image_data_uri(company.logo)" style="padding: 0px; margin: 0px; height: auto; max-width: 200px; max-height: 36px;" t-att-alt="'%s' % company.name"/>
</t>
<t t-else="">
    <h3 style="padding: 0px; margin: 0px; height: auto; max-width: 200px; max-height: 36px;" t-field="company.report_header"/>
</t>

This will use the logo set for the company. So if you change this, the logo get's updated for the emails as well.

I hope this helps!

Avatar
Discard
Related Posts Replies Views Activity
2
Jan 24
9230
1
Mar 21
8862
0
Jan 19
6573
0
Mar 15
3192
1
Mar 15
6366