[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.
This commit is contained in:
Thibault Delavallée
2016-12-30 10:46:12 +01:00
parent 64ea747824
commit 56645335b7
2 changed files with 41 additions and 21 deletions
+34 -11
View File
@@ -42,19 +42,42 @@
<record id="email_template_badge_received" model="mail.template">
<field name="name">Received Badge</field>
<field name="subject">New badge ${object.badge_id.name} granted</field>
<field name="model_id" ref="gamification.model_gamification_badge_user"/>
<field name="partner_to">${object.user_id.partner_id.id}</field>
<field name="lang">${object.user_id.lang}</field>
<field name="body_html"><![CDATA[
<p>Congratulation, you have received the badge <strong>${object.badge_id.name}</strong> !
% if object.sender_id
This badge was granted by <strong>${object.sender_id.name}</strong>.
% endif
</p>
% if object.comment
<p><em>${object.comment}</em></p>
% endif
]]></field>
<field name="body_html" type="xml">
<div>
<p>Congratulations ${object.user_id.name} !</p>
<p>You just received badge <strong>${object.badge_id.name}</strong> !</p>
</div>
<div>
% if object.badge_id.description
<table cellspacing="0" cellpadding="0" border="0" style="width: 600px; margin-top: 5px;">
<tbody><tr>
<td valign="center">
<img src="/web/image/gamification.badge/${object.badge_id.id}/image/80x80" style="padding: 0px; margin: 0px; height: auto; width: 80px;" alt="${user.company_id.name}"/>
</td>
<td valign="center">
<cite>${object.badge_id.description}</cite>
</td>
</tr></tbody>
</table>
% endif
</div>
<div>
<p>
% if object.sender_id
This badge was granted by <strong>${object.sender_id.name}</strong>.
% endif
</p>
<p>
% if object.comment
<em>${object.comment}</em>
% endif
</p>
</div>
</field>
</record>
</data>
</odoo>
+7 -10
View File
@@ -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