From 7b96e7cb22a873ddf3d5779b7c3febf5e974e74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Dec 2022 13:50:13 +0000 Subject: [PATCH] [FIX] mail: correctly display errors when previewing templates In this commit we correctly set 'error_msg' field as computed. As it was not defined as computed, it was not really updated and therefore not displayed in the preview form view. It is now the case. ValueError are now also catched, for example when having badly configured 'partner_ids' field we may face this kind of error, which is now logged in the preview wizard. Task-2710804 (Mail: Clean MailThread Posting API) Part-of: odoo/odoo#99482 --- addons/mail/wizard/mail_template_preview.py | 4 ++-- addons/mail/wizard/mail_template_preview_views.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mail/wizard/mail_template_preview.py b/addons/mail/wizard/mail_template_preview.py index 79644ce3e8f..5916cabdc69 100644 --- a/addons/mail/wizard/mail_template_preview.py +++ b/addons/mail/wizard/mail_template_preview.py @@ -43,7 +43,7 @@ class MailTemplatePreview(models.TransientModel): resource_ref = fields.Reference(string='Record', selection='_selection_target_model') lang = fields.Selection(_selection_languages, string='Template Preview Language') no_record = fields.Boolean('No Record', compute='_compute_no_record') - error_msg = fields.Char('Error Message', readonly=True) + error_msg = fields.Char('Error Message', compute='_compute_mail_template_fields') # Fields same than the mail.template model, computed with resource_ref and lang subject = fields.Char('Subject', compute='_compute_mail_template_fields') email_from = fields.Char('From', compute='_compute_mail_template_fields', help="Sender address") @@ -82,7 +82,7 @@ class MailTemplatePreview(models.TransientModel): ) self._set_mail_attributes(values=mail_values) self.error_msg = False - except UserError as user_error: + except (ValueError, UserError) as user_error: self._set_mail_attributes() self.error_msg = user_error.args[0] finally: diff --git a/addons/mail/wizard/mail_template_preview_views.xml b/addons/mail/wizard/mail_template_preview_views.xml index 228c97956f5..90865d69061 100644 --- a/addons/mail/wizard/mail_template_preview_views.xml +++ b/addons/mail/wizard/mail_template_preview_views.xml @@ -8,7 +8,7 @@

Preview of