From 490e6e0c49530f70a04b86eb1b2b3d8b9587ec29 Mon Sep 17 00:00:00 2001 From: Luis Carlos Bautista Date: Tue, 16 Jul 2024 09:49:14 +0200 Subject: [PATCH] imp: render error as html when body throws exception --- wizard/wizard_poweremail_preview.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wizard/wizard_poweremail_preview.py b/wizard/wizard_poweremail_preview.py index f6e93f4..0fc7f12 100644 --- a/wizard/wizard_poweremail_preview.py +++ b/wizard/wizard_poweremail_preview.py @@ -2,6 +2,7 @@ import sys import traceback +from mako.exceptions import html_error_template from osv import osv, fields from ..poweremail_template import get_value @@ -95,9 +96,11 @@ def action_generate_static_mail(self, cr, uid, ids, context=None): field_value = getattr(template, "def_{}".format(field)) vals[field] = get_value(cr, uid, record_id, field_value, template, ctx) except Exception as e: - import traceback - tb = traceback.format_tb(sys.exc_info()[2]) - vals[field] = ''.join(tb) + if field == 'body_text': + vals[field] = html_error_template().render() + else: + tb = traceback.format_tb(sys.exc_info()[2]) + vals[field] = '{}\n{}'.format(e.message, ''.join(tb)) vals['state'] = 'error' self.write(cr, uid, ids, vals, context=context)