From 158cccfce78bfd58ae83e19306ae7538df0317dd Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Tue, 25 May 2021 21:07:40 +0100 Subject: [PATCH] [FIX] mail_debrand: avoid KeyError: 'body_html' on plain text emails --- mail_debrand/models/mail_render_mixinANDmail_mail.py | 4 +++- mail_debrand/tests/test_mail_debrand.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mail_debrand/models/mail_render_mixinANDmail_mail.py b/mail_debrand/models/mail_render_mixinANDmail_mail.py index a63707f..bbb877b 100644 --- a/mail_debrand/models/mail_render_mixinANDmail_mail.py +++ b/mail_debrand/models/mail_render_mixinANDmail_mail.py @@ -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) diff --git a/mail_debrand/tests/test_mail_debrand.py b/mail_debrand/tests/test_mail_debrand.py index 954b8c6..75e3df0 100644 --- a/mail_debrand/tests/test_mail_debrand.py +++ b/mail_debrand/tests/test_mail_debrand.py @@ -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)