I want to modify the body of an email template, for example email_template_edi_sale
in the module sale
.
Its declaration is inside a <data no update="1">
tag, which means that I have to do a workaround to modify it. So I have decided to make a Python method which does the trick and call it from XML:
XML
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<function model="mail.template" name="_update_existing_mail_templates"/>
</data>
</odoo>
Python
class MailTemplate(models.Model):
_inherit = 'mail.template'
@api.model
def _update_existing_mail_templates(self):
edi_sale = self.env.ref('sale.email_template_edi_sale', False)
if edi_sale:
body_html = _("""<p>Hello customer.</p>""")
edi_sale.write({
'body_html': body_html,
})
This solution works as expected, since when the template is loaded, I only see Hello customer. Now I want to export its translation. The xx.po file is rightly exported since I have available to translate the term <p>Hello customer.</p>
. I translate it to Spanish for example, so I generate the es.po file. Then I update the module and load the translation in Spanish overwriting terms. To check that this worked, I look for the term in the Translated terms menu, and I find it rightly translated. But then, I send by email a sale order of a customer (who has Spanish language set), and the template is loaded with the source text, in English.
I was not able to figure out what is happening.
There is a similar question here: Email template translation Odoo 10
But the guy who asks solved the problem translating the template by hand through the interface. In my case I cannot even apply that solution since the term is rightly translated in the interface.
Any idea to do this OK?