Skip to content

Commit

Permalink
[FIX] website_slides: translate course invite into recipients' language
Browse files Browse the repository at this point in the history
Problem:
when adding attendees to a course, the sent email is not translated into
the recipient's language.

Fix:
Upon sending, translate the email on a per recipient basis,
but **only when** the final message to sent is exactly the same
as the template. (i.e. the body was not edited from the dialog box)

This is a compromise to permit emails being translated while not
breaking the following 2 current features:
* there can be many recipients (with different languages)
* the body is pre-filled with a template but can be edited further
  by the user directly from the dialog box.

opw-3862369
  • Loading branch information
naja628 committed Apr 18, 2024
1 parent ac3964a commit 09cecbe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions addons/website_slides/wizard/slide_channel_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ def action_invite(self):

def _prepare_mail_values(self, slide_channel_partner):
""" Create mail specific for recipient """
subject = self._render_field('subject', slide_channel_partner.ids)[slide_channel_partner.id]
body = self._render_field('body', slide_channel_partner.ids)[slide_channel_partner.id]
set_lang, lang_opt = {}, {}
subject_same_as_template = (self.template_id and self.subject == self.template_id.subject)
if self.body_has_template_value and subject_same_as_template:
lang = self._render_lang(slide_channel_partner.ids)[slide_channel_partner.id]
set_lang, lang_opt = {'set_lang': lang}, {'lang': lang}
subject = self._render_field('subject', slide_channel_partner.ids, **set_lang)[slide_channel_partner.id]
body = self._render_field('body', slide_channel_partner.ids, **set_lang)[slide_channel_partner.id]
# post the message
mail_values = {
'attachment_ids': [(4, att.id) for att in self.attachment_ids],
Expand All @@ -112,7 +117,7 @@ def _prepare_mail_values(self, slide_channel_partner):
'company': self.env.company,
'signature': self.channel_id.user_id.signature,
}
body = self.env['ir.qweb']._render(email_layout_xmlid, template_ctx, engine='ir.qweb', minimal_qcontext=True, raise_if_not_found=False)
body = self.env['ir.qweb']._render(email_layout_xmlid, template_ctx, engine='ir.qweb', minimal_qcontext=True, raise_if_not_found=False, **lang_opt)
if body:
mail_values['body_html'] = self.env['mail.render.mixin']._replace_local_links(body)
else:
Expand Down

0 comments on commit 09cecbe

Please sign in to comment.