Skip to content

Commit

Permalink
ADD hr_gamification_email_notification module
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalid-SerpentCS committed Aug 17, 2020
1 parent 8d4291e commit 43b415b
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 0 deletions.
27 changes: 27 additions & 0 deletions hr_gamification_email_notification/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

======================================
OSI HR Gamification Email Notification
======================================

This module sends an email every week to all the employees with all
the badges awarded during the previous week.


Installation
============

* No specific installation step required.

Configuration
=============

* Basic data configuration.

Credits
=======

* Open Source Integrators <contact@opensourceintegrators.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
5 changes: 5 additions & 0 deletions hr_gamification_email_notification/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
28 changes: 28 additions & 0 deletions hr_gamification_email_notification/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2020 - TODAY, Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "HR Gamification Email Notification",
"version": "12.0.1.0.0",
"license": "AGPL-3",
"author": """Open Source Integrators,
Serpent Consulting Services,
Odoo Community Association (OCA)""",
"summary": """Send Email to all the Employees with all the award given in
the last week.""",
"category": "Human Resources",
"maintainers": ["Khalid-SerpentCS"],
"website": "https://github.com/OCA/hr",
"depends": ["hr_gamification"],
"data": [
"data/ir_cron_data.xml",
"data/mail_template.xml",
"views/badge.xml"
],
"qweb": [],
"auto_install": False,
"application": False,
"installable": True,
"development_status": "Stable",
}
13 changes: 13 additions & 0 deletions hr_gamification_email_notification/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="ir_cron_badge_emails" model="ir.cron">
<field name="name">Badge Awards Emails</field>
<field name="interval_number">1</field>
<field name="interval_type">weeks</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model_id" ref="model_mail_channel"/>
<field name="code">model._send_badge_awards_emails()</field>
<field name="state">code</field>
</record>
</odoo>
60 changes: 60 additions & 0 deletions hr_gamification_email_notification/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<odoo noupdate="1">
<record id="email_template_badge_weekly_awards" model="mail.template">
<field name="name">Received Badges</field>
<field name="subject">Weekly Awards</field>
<field name="model_id" ref="hr_gamification_email_notification.model_mail_channel"/>
<field name="partner_to">${ctx['partner_ids']}</field>
<field name="lang">${object.create_uid.lang}</field>
<field name="body_html" type="xml">
<p>
Dear Employee,<br/>
Below are the award given in the last week.
</p>
<table width="900" border="1" cellpadding="2" style="min-width: 800px; background-color: white; border-collapse:collapse;">
<thead style="background-color: blue;color: white;text-align: left;">
<tr>
<th>Badge</th>
<th width="350">Comment</th>
<th>Awarded On</th>
<th>Awarded To</th>
</tr>
</thead>
<tbody>
% set badges = ctx.get('badge_ids', False)
% for badge in badges
<tr>
<td style="color: blue;">${badge.badge_name or ''}</td>
<td>${badge.comment or ''}</td>
<td>${badge.create_date or ''}</td>
<td>${badge.user_id.name or ''}</td>
</tr>
% endfor
</tbody>
</table>

<div align="center" style="min-width: 590px;">
<table border="0" cellpadding="0" cellspacing="0" width="590" style=" font-family: 'Verdana Regular'; color: #454748; min-width: 590px; background-color: white; font-size: 11px; padding: 0px 8px 0px 8px; border-collapse:separate;">
<tr>
<td valign="middle" align="left">
${user.company_id.name}
</td>
<td valign="middle" align="right" style="opacity: 0.7;">
${user.company_id.phone}
% if user.company_id.email:
| <a href="'mailto:%s' % ${user.company_id.email}" style="text-decoration:none; color: #454748;">
${user.company_id.email}
</a>
% endif
% if user.company_id.website:
| <a href="${user.company_id.website}" style="text-decoration:none; color: #454748;">
${user.company_id.website}
</a>
% endif
</td>
</tr>
</table>
</div>
</field>
</record>
</odoo>

5 changes: 5 additions & 0 deletions hr_gamification_email_notification/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import mail_channel
39 changes: 39 additions & 0 deletions hr_gamification_email_notification/models/mail_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2020 Open Source Integrators
# Copyright (C) 2020 Serpent Consulting Services
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import timedelta

from odoo import api, fields, models


class MailChannel(models.Model):

_inherit = 'mail.channel'

@api.model
def _send_badge_awards_emails(self):
channel_general = self.env['mail.channel'].search(
[('name', '=', 'general')], limit=1)
partner_ids = []
for partner_id in channel_general.channel_last_seen_partner_ids:
partner_ids.append(str(partner_id.partner_id.id))
partner_ids = ','.join(partner_ids)
template = self.env.ref(
'hr_gamification_email_notification.'
'email_template_badge_weekly_awards')
date_before_aweek = fields.Date.today() - timedelta(days=7)
badge_ids = self.env['gamification.badge.user'].search(
[('create_date', '<', fields.Date.today()),
('create_date', '>=', date_before_aweek)])
if badge_ids:
channel_general.with_context(
{'badge_ids': badge_ids,
'partner_ids': partner_ids}
).message_post_with_template(
template.id,
model=self._name,
composition_mode='mass_mail'
)

return True
2 changes: 2 additions & 0 deletions hr_gamification_email_notification/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Mohammed Khalid <m.khalid@serpentcs.com>
2 changes: 2 additions & 0 deletions hr_gamification_email_notification/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Open Source Integrators <https://www.opensourceintegrators.com>
* Serpent Consulting Services Pvt Ltd <https://www.serpentcs.com>
2 changes: 2 additions & 0 deletions hr_gamification_email_notification/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module sends an email every week to all the employees with all
the badges awarded during the previous week.
1 change: 1 addition & 0 deletions hr_gamification_email_notification/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Search for "Received badges" to review/adjust the email content
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions hr_gamification_email_notification/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_mail_channel
38 changes: 38 additions & 0 deletions hr_gamification_email_notification/tests/test_mail_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime
from dateutil.relativedelta import relativedelta

from odoo.tests import common


class TestMailChannel(common.TransactionCase):

def setUp(self):
super(TestMailChannel, self).setUp()
employees_group = self.env.ref('base.group_user')
self.user_ids = employees_group.users
self.test_employee = self.browse_ref('hr.employee_al')

self.robot = self.env['res.users'].with_context(
no_reset_password=True).create({
'name': 'R2D2',
'login': 'r2d2@odoo.com',
'email': 'r2d2@odoo.com',
'groups_id': [(6, 0, [employees_group.id])]
})
self.badge_good_job = self.env.ref('gamification.badge_good_job')
self.channel_general = self.env['mail.channel'].search(
[('name', '=', 'general')], limit=1)

def test_send_badge_awards_emails(self):
self.test_employee.user_id = self.robot.id
wiz = self.env['gamification.badge.user.wizard'].create({
'badge_id': self.badge_good_job.id,
'employee_id': self.test_employee.id
})
wiz.create_date = datetime.datetime.now() - relativedelta(days=1)
wiz.action_grant_badge()
self.assertTrue(
self.channel_general._send_badge_awards_emails(),
"Could not sent emails")
26 changes: 26 additions & 0 deletions hr_gamification_email_notification/views/badge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<odoo>
<record id="badge_user_list_view" model="ir.ui.view">
<field name="name">Badge User List View</field>
<field name="model">gamification.badge.user</field>
<field name="arch" type="xml">
<tree string="Badge User List" create="false">
<field name="badge_name"/>
<field name="badge_id"/>
<field name="user_id"/>
<field name="sender_id"/>
<field name="challenge_id"/>
</tree>
</field>
</record>

<record id="badge_user_list_action" model="ir.actions.act_window">
<field name="name">User Badge</field>
<field name="res_model">gamification.badge.user</field>
<field name="view_mode">tree</field>
<field name="domain">[]</field>
<field name="context">{}</field>
</record>

<menuitem id="gamification_badge_user_list_menu_hr" parent="hr_gamification.menu_hr_gamification" action="badge_user_list_action"
groups="hr.group_hr_user"/>
</odoo>

0 comments on commit 43b415b

Please sign in to comment.