[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
This commit is contained in:
Thibault Delavallée
2023-01-17 20:58:30 +01:00
parent 44a316275d
commit 7b96e7cb22
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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:
@@ -8,7 +8,7 @@
<form string="Email Preview">
<h3>Preview of <field name="mail_template_id" readonly="1" nolabel="1" options="{'no_open' : True}"/></h3>
<div class="alert alert-danger" role="alert" attrs="{'invisible' : [('error_msg', '=', False)]}">
<field name="error_msg" />
<field name="error_msg"/>
</div>
<field name="no_record" invisible="1"/>
<div class="container">