[FIX] purchase_request: render HTML notification body correctly - #3117
Open
les-adhoc wants to merge 1 commit into
Open
[FIX] purchase_request: render HTML notification body correctly#3117les-adhoc wants to merge 1 commit into
les-adhoc wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 areal v19 database; the same broken email reached the user who approved the
request.
Root cause
PurchaseOrder._purchase_request_confirm_message_contentbuilt the body as aplain
strand passedhtml_escape(line["name"])— which returns aMarkup— as an argument toself.env._().In Odoo 19,
Environment._escapes the entire translated string wheneverany of its arguments is a
Markup:So the surrounding
<h3>/<ul>/<li>markup got escaped together with thevalue, and rendered as text.
PurchaseRequestAllocation._purchase_request_confirm_done_message_contenthad the exact same pattern (HTML in the msgid +
html_escape()argument toself.env._()) and is fixed here too.Fix
Build the body with
Markup(...).format(...)from the start, keep thetranslatable strings free of HTML, and apply
html_escape()outside ofself.env._()— mirroring the existing_purchase_request_confirm_done_message_contentmethod which already does itcorrectly. The redundant
Markup(message)wrap at the call sites is droppedsince the builders now return
Markup.Translatable terms (
.pot) updated accordingly: the HTML is no longer partof the msgids.
Notes
of escaped.
19.0.1.0.2.