Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions email_template_qweb/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,39 @@ class MailTemplate(models.Model):

def generate_email(self, res_ids, fields):
multi_mode = True
IrQweb = self.env["ir.qweb"]

if isinstance(res_ids, int):
res_ids = [res_ids]
multi_mode = False
result = super(MailTemplate, self).generate_email(res_ids, fields=fields)
for lang, (_template, _template_res_ids) in self._classify_per_lang(

result = super().generate_email(res_ids, fields=fields)

for lang, (_template, template_res_ids) in self._classify_per_lang(
res_ids
).items():
self_with_lang = self.with_context(lang=lang)
for res_id in res_ids:
if self.body_type == "qweb_view" and (

# bind QWeb AFTER switching lang context
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 (
not fields or "body_html" in fields
):
for record in self_with_lang.env[self.model].browse(res_id):
body_html = IrQweb._render(
self_with_lang.body_view_id.id,
{"object": record, "email_template": self_with_lang},
)
# Some wizards, like when sending a sales order, need this
# fix to display accents correctly
body_html = tools.ustr(body_html)
result[res_id][
"body_html"
] = self_with_lang._render_template_postprocess(
{res_id: body_html}
)[
res_id
]
result[res_id]["body"] = tools.html_sanitize(
result[res_id]["body_html"]
)
record = self_with_lang.env[self_with_lang.model].browse(res_id)
body_html = IrQweb._render(
self_with_lang.body_view_id.id,
{"object": record, "email_template": self_with_lang},
)
body_html = tools.ustr(body_html)
result[res_id][
"body_html"
] = self_with_lang._render_template_postprocess(
{res_id: body_html}
)[
Copy link

Choose a reason for hiding this comment

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

Bit overkill to spread [res_id] over three lines.

Copy link
Author

Choose a reason for hiding this comment

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

It looks that way due to the pylint but the res_id used is from the for loop.

Copy link

Choose a reason for hiding this comment

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

Maybe I was not clear, I just meant that lines 48 - 50 could be on one line, making it all a bit more compact and readable.

Copy link
Author

@KKamaa KKamaa Jan 6, 2026

Choose a reason for hiding this comment

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

updated the readability on the lines affected

res_id
]
result[res_id]["body"] = tools.html_sanitize(
result[res_id]["body_html"]
)

return result if multi_mode else result[res_ids[0]]