Skip to content

[FIX] purchase_request: render HTML notification body correctly - #3117

Open
les-adhoc wants to merge 1 commit into
OCA:19.0from
adhoc-dev:19.0-fix-purchase_request-html-notification
Open

[FIX] purchase_request: render HTML notification body correctly#3117
les-adhoc wants to merge 1 commit into
OCA:19.0from
adhoc-dev:19.0-fix-purchase_request-html-notification

Conversation

@les-adhoc

Copy link
Copy Markdown

Problem

When a purchase order created from a purchase request is confirmed, the
notification posted on the request showed its HTML tags (<h3>, <ul>,
<li>) as literal text instead of rendered markup. Reproducible on a
real v19 database; the same broken email reached the user who approved the
request.

Root cause

PurchaseOrder._purchase_request_confirm_message_content built the body as a
plain str and passed html_escape(line["name"]) — which returns a
Markup — as an argument to self.env._().

In Odoo 19, Environment._ escapes the entire translated string whenever
any of its arguments is a Markup:

# odoo/tools/translate.py
if any(isinstance(a, Markup) for a in args.values()):
    translation = escape(translation)

So the surrounding <h3>/<ul>/<li> markup got escaped together with the
value, and rendered as text.

PurchaseRequestAllocation._purchase_request_confirm_done_message_content
had the exact same pattern (HTML in the msgid + html_escape() argument to
self.env._()) and is fixed here too.

Fix

Build the body with Markup(...).format(...) from the start, keep the
translatable strings free of HTML, and apply html_escape() outside of
self.env._() — mirroring the existing
_purchase_request_confirm_done_message_content method which already does it
correctly. The redundant Markup(message) wrap at the call sites is dropped
since the builders now return Markup.

Translatable terms (.pot) updated accordingly: the HTML is no longer part
of the msgids.

Notes

  • No functional/data change; output is identical HTML, now rendered instead
    of escaped.
  • Version bumped to 19.0.1.0.2.

The purchase order confirmation notification posted on the purchase
request rendered its <h3>/<ul>/<li> tags as literal text in Odoo 19.

The body was built as a plain str while html_escape() (which returns a
Markup) was passed as an argument to self.env._(). In Odoo 19 the
translation function escapes the whole translated string when any of its
arguments is a Markup (odoo/tools/translate.py), so the surrounding HTML
markup ended up escaped too.

Build the message with Markup().format() from the start, keeping the
translatable strings free of HTML and applying html_escape() outside of
self.env._(), mirroring the sibling _purchase_request_confirm_done_message_content
method. The same broken pattern in purchase_request_allocation is fixed
as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants