Skip to content

[16.0][FIX] email_template_qweb: use language-aware env for rendering QWeb#1784

Merged
OCA-git-bot merged 1 commit intoOCA:16.0from
Therp:16.0-13011-fix-email-template-qweb
Feb 20, 2026
Merged

[16.0][FIX] email_template_qweb: use language-aware env for rendering QWeb#1784
OCA-git-bot merged 1 commit intoOCA:16.0from
Therp:16.0-13011-fix-email-template-qweb

Conversation

@KKamaa
Copy link

@KKamaa KKamaa commented Dec 31, 2025

fix bug where in email_template_qweb module: the QWeb renderer (ir.qweb) is instantiated once from the original environment (self.env) before the code switches into the per-language context:

  • Subject is rendered via the "normal" mail.template rendering path that uses the per-language self_with_lang context -> it follows template.lang.
  • Body is rendered by ir.qweb._render(...) using an IrQweb recordset created before lang was applied -> it keeps whatever env.lang was at the moment generate_email() started (e.g. the website request language, current user language, etc.), which explains the "random" English/Dutch mix.

Copy link

@thomaspaulb thomaspaulb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code approved, just the commit message should change to the OCA standard:

[FIX] email_template_qweb: use language-aware env for rendering QWeb

More detailed information... (maybe can leave out in this case, summary is clear)

Copy link

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 One minor remark but for the rest LGTM

@KKamaa KKamaa force-pushed the 16.0-13011-fix-email-template-qweb branch from c36282d to 4ffe344 Compare January 4, 2026 20:33
@KKamaa KKamaa changed the title Draft: [16.0][FIX] #13011 Bug Draft: [16.0][FIX] email_template_qweb: use language-aware env for rendering QWeb Jan 4, 2026
@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@thomaspaulb
Copy link

@OCA/social-maintainers This is ready for merge

@NL66278
Copy link

NL66278 commented Jan 6, 2026

@KKamaa Please remove the Draft: status of this PR, as that might stop people from merging.

@KKamaa KKamaa changed the title Draft: [16.0][FIX] email_template_qweb: use language-aware env for rendering QWeb [16.0][FIX] email_template_qweb: use language-aware env for rendering QWeb Jan 6, 2026
@KKamaa KKamaa requested review from NL66278 and ntsirintanis January 6, 2026 21:34
Copy link

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Already looked good. Now even better ;-)

@NL66278
Copy link

NL66278 commented Feb 5, 2026

@KKamaa Please take up my new comment and then merge commits.

@KKamaa KKamaa force-pushed the 16.0-13011-fix-email-template-qweb branch from c51da58 to 479191e Compare February 6, 2026 09:00
IrQweb = self_with_lang.env["ir.qweb"]

for res_id in template_res_ids: # ✅ use the bucketed ids
if self_with_lang.body_type == "qweb_view" and (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this can be tested straight after line 24:
result = super().generate_email(res_ids, fields=fields)

If this is followed by

if self.body_type != "qweb_view" or (fields and "body_html" not in fields):
    return result

A lot of processing can be avoided if we do not in the end modify the result anyway, and the code will have an indentation level less.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it, the early exit, if body isn't a qweb_view or body_html is in fields.

@NL66278
Copy link

NL66278 commented Feb 6, 2026

@KKamaa One more remark, check whether you agree, and still need to smash commits.

@KKamaa KKamaa force-pushed the 16.0-13011-fix-email-template-qweb branch from d4d38e2 to 31b9e5b Compare February 6, 2026 12:22
IrQweb = self_with_lang.env["ir.qweb"]

for res_id in template_res_ids: # ✅ use the bucketed ids
if self_with_lang.body_type == "qweb_view" and (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So drop this if and de-indent everything that follows.

self_with_lang = self.with_context(lang=lang)
for res_id in res_ids:
if self.body_type == "qweb_view" and (

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also do not add blank lines everywhere. Basically, with some exceptions, the body of a method should not contain blank lines. They make it more difficult to see all the logic on one page.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@KKamaa KKamaa force-pushed the 16.0-13011-fix-email-template-qweb branch from 8233f36 to f7ceb71 Compare February 9, 2026 16:16
@KKamaa
Copy link
Author

KKamaa commented Feb 10, 2026

@NL66278 there is a conflict coming from your branch https://github.com/Therp/social/tree/16.0-email_template_qweb-copy-view-also

@NL66278
Copy link

NL66278 commented Feb 17, 2026

@OCA/social-maintainers Can somebody please merge this?

@hbrunn
Copy link
Member

hbrunn commented Feb 17, 2026

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-1784-by-hbrunn-bump-patch, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Feb 17, 2026
Signed-off-by hbrunn
@OCA-git-bot
Copy link
Contributor

@hbrunn your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-1784-by-hbrunn-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@hbrunn
Copy link
Member

hbrunn commented Feb 17, 2026

merging will only work after OCA/oca-addons-repo-template#333 is merged and applied to this branch

@NL66278
Copy link

NL66278 commented Feb 20, 2026

@hbrunn Merging should work now, I made a PR for the repo template upgrade and it was immediately merged by Pedro.

@hbrunn
Copy link
Member

hbrunn commented Feb 20, 2026

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-1784-by-hbrunn-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit dccf29a into OCA:16.0 Feb 20, 2026
1 check passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at f796174. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants