[FIX] mail_debrand: avoid KeyError: 'body_html' on plain text emails

This commit is contained in:
Daniel Reis 2021-05-25 21:07:40 +01:00 committed by AlvaroTForgeFlow
parent f6159689b2
commit 158cccfce7
2 changed files with 14 additions and 1 deletions

View File

@ -101,7 +101,9 @@ class MailMail(models.AbstractModel):
values_list[index]["body_html"] = self.env[
"mail.render.mixin"
].remove_href_odoo(
values_list[index]["body_html"], remove_parent=0, remove_before=1
values_list[index].get("body_html", ""),
remove_parent=0,
remove_before=1,
)
return super().create(values_list)

View File

@ -54,3 +54,14 @@ class TestMailDebrand(common.TransactionCase):
._render_template(paynow_arch, "ir.ui.view", [self.paynow_template])
)
self.assertNotIn("Aangeboden door", res)
def test_plaintext_email(self):
MailMessage = self.env["mail.mail"]
email_values = {
"email_from": "customer@example.com",
"subject": "Hello",
"email_to": "contact@example.com",
"reply_to": "contact@example.com",
}
# No exception expected
MailMessage.create(email_values)