1- # Copyright 2016 Therp BV <http://therp.nl>
1+ # Copyright 2016-2026 Therp BV <http://therp.nl>
22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33from odoo import fields , models , tools
44
@@ -20,37 +20,25 @@ def generate_email(self, res_ids, fields):
2020 if isinstance (res_ids , int ):
2121 res_ids = [res_ids ]
2222 multi_mode = False
23-
2423 result = super ().generate_email (res_ids , fields = fields )
25-
2624 if self .body_type != "qweb_view" or (fields and "body_html" not in fields ):
2725 return result if multi_mode else result [res_ids [0 ]]
28-
2926 for lang , (_template , template_res_ids ) in self ._classify_per_lang (
3027 res_ids
3128 ).items ():
3229 self_with_lang = self .with_context (lang = lang )
33-
34- # bind QWeb AFTER switching lang context
3530 IrQweb = self_with_lang .env ["ir.qweb" ]
36-
37- for res_id in template_res_ids : # ✅ use the bucketed ids
38- if self_with_lang .body_type == "qweb_view" and (
39- not fields or "body_html" in fields
40- ):
41- record = self_with_lang .env [self_with_lang .model ].browse (res_id )
42- result_res_id = result [res_id ]
43- body_html = IrQweb ._render (
44- self_with_lang .body_view_id .id ,
45- {"object" : record , "email_template" : self_with_lang },
46- )
47- body_html = tools .ustr (body_html )
48- rendered_post_temp = self_with_lang ._render_template_postprocess (
49- {res_id : body_html }
50- )
51- result_res_id ["body_html" ] = rendered_post_temp [res_id ]
52- result_res_id ["body" ] = tools .html_sanitize (
53- result_res_id ["body_html" ]
54- )
55-
31+ for res_id in template_res_ids :
32+ record = self_with_lang .env [self_with_lang .model ].browse (res_id )
33+ result_res_id = result [res_id ]
34+ body_html = IrQweb ._render (
35+ self_with_lang .body_view_id .id ,
36+ {"object" : record , "email_template" : self_with_lang },
37+ )
38+ body_html = tools .ustr (body_html )
39+ rendered_post_temp = self_with_lang ._render_template_postprocess (
40+ {res_id : body_html }
41+ )
42+ result_res_id ["body_html" ] = rendered_post_temp [res_id ]
43+ result_res_id ["body" ] = tools .html_sanitize (result_res_id ["body_html" ])
5644 return result if multi_mode else result [res_ids [0 ]]
0 commit comments