From 56645335b7bae0415242ec51193e493119a58879 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Thu, 24 Nov 2016 17:52:59 +0100
Subject: [PATCH] [IMP] gamification: improve email sent when granting a badge
Give some details about the badge: its description, its image, who granted
it, ... Otherwise it is quite complicated to understand the email content.
Thanks to @mart-e who reviewed and tested.
---
addons/gamification/data/badge.xml | 45 ++++++++++++++++++++++-------
addons/gamification/models/badge.py | 17 +++++------
2 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/addons/gamification/data/badge.xml b/addons/gamification/data/badge.xml
index a928a342122..7af0b859048 100644
--- a/addons/gamification/data/badge.xml
+++ b/addons/gamification/data/badge.xml
@@ -42,19 +42,42 @@
Received Badge
+ New badge ${object.badge_id.name} granted
+ ${object.user_id.partner_id.id}
${object.user_id.lang}
- Congratulation, you have received the badge ${object.badge_id.name} !
- % if object.sender_id
- This badge was granted by ${object.sender_id.name}.
- % endif
-
-
- % if object.comment
- ${object.comment}
- % endif
- ]]>
+
+
+
Congratulations ${object.user_id.name} !
+
You just received badge ${object.badge_id.name} !
+
+
+% if object.badge_id.description
+
+
+
+
+ |
+
+ ${object.badge_id.description}
+ |
+
+
+% endif
+
+
+
+% if object.sender_id
+ This badge was granted by ${object.sender_id.name}.
+% endif
+
+
+% if object.comment
+ ${object.comment}
+% endif
+
+
+
diff --git a/addons/gamification/models/badge.py b/addons/gamification/models/badge.py
index 78ed035da4d..3ca11577c33 100644
--- a/addons/gamification/models/badge.py
+++ b/addons/gamification/models/badge.py
@@ -33,18 +33,15 @@ class BadgeUser(models.Model):
The stats counters are incremented
:param ids: list(int) of badge users that will receive the badge
"""
- Template = self.env['mail.template']
- template_id = self.env.ref('gamification.email_template_badge_received')
+ template = self.env.ref('gamification.email_template_badge_received')
for badge_user in self:
- # .ids would trigger the "multi mode" which returns a mapping of
- # res_id to templates
- template = template_id.get_email_template(badge_user.id)
- body_html = Template.with_context(template._context).render_template(template.body_html, 'gamification.badge.user', badge_user.id)
- badge_user.user_id.message_post(
- body=body_html,
- subtype='gamification.mt_badge_granted',
- partner_ids=badge_user.user_id.partner_id.ids
+ self.env['mail.thread'].message_post_with_template(
+ template.id,
+ model=badge_user._name,
+ res_id=badge_user.id,
+ composition_mode='mass_mail',
+ partner_ids=badge_user.user_id.partner_id.ids,
)
return True