diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-04-05 09:15:54 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-03-24 10:24:18 +0000 |
| commit | a03f6483d6be83a81eac6e8f667ce317c8007dbe (patch) | |
| tree | 6daaefc4832be7197a86119a648d7cd81402c250 /addons/gamification/models | |
| parent | aa31e67716f19ad84145ecb35b0cda07e2143b83 (diff) | |
[REF] mail: clean code about rendering in mail_template
PURPOSE
Clean and rename code about language management and template rendering in mail
template model.
SPECIFICATIONS
Clean method naming and try to make code easier to understand and call. Also
add and/or clean docstrings of rendering methods.
Notably
* ``_classify_per_lang``: for each lang-contextualized template, give the list
of record ids;
* ``_render_template``: now working only on a valid list of IDs instead of
allowing both int / list and having a return type depending on the input
type. It allows to simplify code and delegate some processing to callers;
Introduce new API method
* ``_render_lang``: for each record id return the lang matching it;
* ``_render_field``: render a field of mail.template, on given set of record
ids. Usage: template._render_field('body_html', records.ids). Language
computation is available for this method;
Remove the "multi mode" support of rendering that either returned a rendered
value, either a dict based on given ids. Now all methods always work in batch
and caller have to fetch the correct result if necessary.
LINKS
Task ID 1963529
Community PR odoo/odoo#32397
Diffstat (limited to 'addons/gamification/models')
| -rw-r--r-- | addons/gamification/models/challenge.py | 8 | ||||
| -rw-r--r-- | addons/gamification/models/goal.py | 5 |
2 files changed, 3 insertions, 10 deletions
diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index 19aa131270e..c424a8c4b28 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -551,11 +551,10 @@ class Challenge(models.Model): challenge = self - MailTemplates = self.env['mail.template'] if challenge.visibility_mode == 'ranking': lines_boards = challenge._get_serialized_challenge_lines(restrict_goals=subset_goals) - body_html = MailTemplates.with_context(challenge_lines=lines_boards)._render_template(challenge.report_template_id.body_html, 'gamification.challenge', challenge.id) + body_html = challenge.report_template_id.with_context(challenge_lines=lines_boards)._render_field('body_html', challenge.ids)[challenge.id] # send to every follower and participant of the challenge challenge.message_post( @@ -576,10 +575,7 @@ class Challenge(models.Model): if not lines: continue - body_html = MailTemplates.with_user(user).with_context(challenge_lines=lines)._render_template( - challenge.report_template_id.body_html, - 'gamification.challenge', - challenge.id) + body_html = challenge.report_template_id.with_user(user).with_context(challenge_lines=lines)._render_field('body_html', challenge.ids)[challenge.id] # notify message only to users, do not post on the challenge challenge.message_notify( diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index d6dd9e5a919..3d528a5cab8 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -213,10 +213,7 @@ class Goal(models.Model): return {} # generate a reminder report - template = self.env.ref('gamification.email_template_goal_reminder')\ - .get_email_template(self.id) - body_html = self.env['mail.template'].with_context(template._context)\ - ._render_template(template.body_html, 'gamification.goal', self.id) + body_html = self.env.ref('gamification.email_template_goal_reminder')._render_field('body_html', self.ids, compute_lang=True)[self.id] self.message_notify( body=body_html, partner_ids=[self.user_id.partner_id.id], |
