summaryrefslogtreecommitdiff
path: root/addons/sms/models
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-03-06 13:17:20 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-24 10:24:42 +0000
commit2835e0ba38f67f76b7f43948290050dcc68cd9db (patch)
tree369ae761539aca4cef909656cfd6e63b6d56af0c /addons/sms/models
parent822f468059c9702b0898016e7bfbaf036a2c4036 (diff)
[MOV] mail, sms: move language computation in render mixin directly
PURPOSE Merge rendering tools used in mail and sms templates as well as partially in mailings and move them directly in mail.render.mixin. SPECIFICATIONS Move tools related to language computation from mail.template model to the mail.render.mixin. It allows to update both * mail.template: simply update calls accordingly; * sms.template: remove code doing what is now available through mail.render .mixin inherit; Lang field is moved to mail.render.mixin as it is used notably for the language computation. It therefore adds the field on mailing.mailing model although not used currently. LINKS Task ID 1963529 Community PR odoo/odoo#32397
Diffstat (limited to 'addons/sms/models')
-rw-r--r--addons/sms/models/mail_thread.py3
-rw-r--r--addons/sms/models/sms_template.py43
2 files changed, 1 insertions, 45 deletions
diff --git a/addons/sms/models/mail_thread.py b/addons/sms/models/mail_thread.py
index 86713fddc24..820c5230cfe 100644
--- a/addons/sms/models/mail_thread.py
+++ b/addons/sms/models/mail_thread.py
@@ -180,8 +180,7 @@ class MailThread(models.AbstractModel):
if not template and template_xmlid:
template = self.env.ref(template_xmlid, raise_if_not_found=False)
if template:
- template_w_lang = template._get_context_lang_per_id(self.ids)[self.id]
- body = template._render_template(template_w_lang.body, self._name, self.ids)[self.id]
+ body = template._render_field('body', self.ids, compute_lang=True)[self.id]
else:
body = self.env['sms.template']._render_template(template_fallback, self._name, self.ids)[self.id]
return self._message_sms(body, partner_ids=partner_ids, **kwargs)
diff --git a/addons/sms/models/sms_template.py b/addons/sms/models/sms_template.py
index a2b2300051b..fb5b8877e87 100644
--- a/addons/sms/models/sms_template.py
+++ b/addons/sms/models/sms_template.py
@@ -24,9 +24,6 @@ class SMSTemplate(models.Model):
help="The type of document this template can be used with", ondelete='cascade')
model = fields.Char('Related Document Model', related='model_id.model', index=True, store=True, readonly=True)
body = fields.Char('Body', translate=True, required=True)
- lang = fields.Char('Language', help="Use this field to either force a specific language (ISO code) or dynamically "
- "detect the language of your recipient by a placeholder expression "
- "(e.g. ${object.partner_id.lang})")
# Use to create contextual action (same as for email template)
sidebar_action_id = fields.Many2one('ir.actions.act_window', 'Sidebar action', readonly=True, copy=False,
help="Sidebar action to make this template available on records "
@@ -67,43 +64,3 @@ class SMSTemplate(models.Model):
if template.sidebar_action_id:
template.sidebar_action_id.unlink()
return True
-
- # ------------------------------------------------------------
- # RENDERING
- # ------------------------------------------------------------
-
- def _get_context_lang_per_id(self, res_ids):
- self.ensure_one()
- if res_ids is None:
- return {None: self}
-
- if self.env.context.get('template_preview_lang'):
- lang = self.env.context.get('template_preview_lang')
- results = dict((res_id, self.with_context(lang=lang)) for res_id in res_ids)
- else:
- rendered_langs = self._render_template(self.lang, self.model, res_ids)
- results = dict(
- (res_id, self.with_context(lang=lang) if lang else self)
- for res_id, lang in rendered_langs.items())
-
- return results
-
- def _get_ids_per_lang(self, res_ids):
- self.ensure_one()
-
- rids_to_tpl = self._get_context_lang_per_id(res_ids)
- tpl_to_rids = {}
- for res_id, template in rids_to_tpl.items():
- tpl_to_rids.setdefault(template._context.get('lang', self.env.user.lang), []).append(res_id)
-
- return tpl_to_rids
-
- def _get_translated_bodies(self, res_ids):
- """ return sms translated bodies into a dict {'res_id':'body'} """
- self.ensure_one()
- lang_to_rids = self._get_ids_per_lang(res_ids)
- all_bodies = {}
- for lang, rids in lang_to_rids.items():
- template = self.with_context(lang=lang)
- all_bodies.update(template._render_template(template.body, self.model, rids))
- return all_bodies