[FIX] support all languages, no need of translations

This commit is contained in:
Andrea 2020-09-17 11:54:25 +02:00 committed by AlvaroTForgeFlow
parent 6e2f654b7e
commit 2a3e341a64
3 changed files with 33 additions and 5 deletions

View File

@ -7,10 +7,10 @@
{
"name": "Mail Debrand",
"summary": "Remove Odoo branding in sent emails",
"version": "13.0.0.0.1",
"version": "13.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social/",
"author": "Tecnativa, Eficent, Odoo Community Association (OCA)",
"author": "Tecnativa, Eficent, Onestein, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["mail"],

View File

@ -1,5 +1,6 @@
# Copyright 2019 O4SB - Graeme Gellatly
# Copyright 2019 Tecnativa - Ernesto Tejeda
# Copyright 2020 Onestein - Andrea Stirpe
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import re
@ -11,12 +12,22 @@ from odoo import _, api, models
class MailTemplate(models.Model):
_inherit = "mail.template"
@api.model
def _debrand_translated_words(self):
def _get_translated(word):
return self.env["ir.translation"]._get_source(
"ir.ui.view,arch_db", "model_terms", self.env.lang, word
)
odoo_word = _get_translated("Odoo") or _("Odoo")
powered_by = _get_translated("Powered by") or _("Powered by")
using_word = _get_translated("using") or _("using")
return odoo_word, powered_by, using_word
@api.model
def _debrand_body(self, html):
using_word = _("using")
odoo_word = _("Odoo")
odoo_word, powered_by, using_word = self._debrand_translated_words()
html = re.sub(using_word + "(.*)[\r\n]*(.*)>" + odoo_word + r"</a>", "", html)
powered_by = _("Powered by")
if powered_by not in html:
return html
root = htmltree.fromstring(html)

View File

@ -1,7 +1,9 @@
# Copyright 2017 Tecnativa - Pedro M. Baeza
# Copyright 2020 Onestein - Andrea Stirpe
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import common
from odoo.tools.misc import mute_logger
class TestMailDebrand(common.TransactionCase):
@ -19,3 +21,18 @@ class TestMailDebrand(common.TransactionCase):
self.assertIn("Powered by", self.paynow_arch)
res = self.env["mail.template"]._debrand_body(self.paynow_arch)
self.assertNotIn("Powered by", res)
def test_lang_paynow_debrand(self):
with mute_logger("odoo.addons.base.models.ir_translation"):
self.env["base.language.install"].create(
{"lang": "nl_NL", "overwrite": True}
).lang_install()
with mute_logger("odoo.tools.translate"):
self.env["base.update.translations"].create({"lang": "nl_NL"}).act_update()
ctx = dict(lang="nl_NL")
paynow_template = self.env.ref("mail.mail_notification_paynow")
paynow_arch = paynow_template.with_context(ctx).arch
self.assertIn("Aangeboden door", paynow_arch)
res = self.env["mail.template"].with_context(ctx)._debrand_body(paynow_arch)
self.assertNotIn("Aangeboden door", res)