From a7116ab3c0d2ded51c97ebe1081cdb55d6712b46 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Wed, 20 Mar 2024 13:16:50 +0100 Subject: [PATCH] [FIX] util/snippets: generate HTML instead of XML for mailing.mailing The `convert_html_content` tool writes XML values if a change happened. This is a problem for the fields of `mailing.mailing` because they strictly expect HTML content. E.g. if `` becomes ``, the wysiwyg editor displays an empty template instead of the actual content. This commit avoids this by making the writes to the fields of `mailing.mailing` formatted in HTML. task-3797854 --- src/util/snippets.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util/snippets.py b/src/util/snippets.py index a5415fe1..580daa85 100644 --- a/src/util/snippets.py +++ b/src/util/snippets.py @@ -186,6 +186,12 @@ class HTMLConverter: def __init__(self, callback, selector=None): self.selector = selector self.callback = make_pickleable_callback(callback) + self.format = "xml" + + def set_format(self, format): + # Using a format string instead of html and etree because self + # needs to be pickleable. + self.format = format def has_changed(self, els): if self.selector: @@ -206,8 +212,9 @@ def __call__(self, content): parser=utf8_parser, ) has_changed = self.has_changed(els) + formatter = etree if self.format == "xml" else html new_content = ( - re.sub(r"(^|$)", "", etree.tostring(els, encoding="unicode").strip()) + re.sub(r"(^|$)", "", formatter.tostring(els, encoding="unicode").strip()) if has_changed else content ) @@ -322,6 +329,8 @@ def convert_html_content( :param dict kwargs: extra keyword arguments to pass to :func:`convert_html_column` """ + if "set_format" in dir(converter_callback): + converter_callback.set_format('xml') convert_html_columns( cr, "ir_ui_view", @@ -332,4 +341,8 @@ def convert_html_content( ) for table, columns in html_fields(cr): + if "set_format" in dir(converter_callback): + # mass_mailing requires HTML + converter = "html" if table == "mailing_mailing" else "xml" + converter_callback.set_format(converter) convert_html_columns(cr, table, columns, converter_callback, where_column=where_column, **kwargs)