forked from OCA/hr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] hr_holiday_notify_employee_manager: Notify by mail the manager …
…of the employee requesting the leave. (OCA#331)
- Loading branch information
1 parent
f11ed68
commit 9a91ebe
Showing
9 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.. 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 | ||
|
||
================================== | ||
HR Holiday Notify Employee Manager | ||
================================== | ||
|
||
This module extends the functionality of the Leaves App to make possible | ||
to notify by mail the manager of the employee requesting the leave. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
#. Go to *Settings > Users > Companies*. | ||
#. In the company form go to the *Configuration* tab and in the *Leaves | ||
Management* section. | ||
#. Check *Leave Requests notified to employee's manager* box. | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Go to *Leaves > My Leaves > Leaves Request* and create a leave request to be | ||
approved. | ||
#. Your manager will be notified by email. | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/116/9.0 | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/hr/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Lois Rilo <lois.rilo@eficent.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "HR Holiday Notify Employee Manager", | ||
"summary": "Notify employee's manager by mail on Leave Requests " | ||
"creation.", | ||
"version": "9.0.1.0.0", | ||
"category": "Human Resources", | ||
"website": "https://odoo-community.org/", | ||
"author": "Eficent, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": ["hr_holidays"], | ||
"data": ['views/res_company_view.xml'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import hr_holidays | ||
from . import res_company |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models | ||
|
||
|
||
class HrHolidays(models.Model): | ||
_inherit = 'hr.holidays' | ||
|
||
@api.multi | ||
def _get_approvers_to_notify(self): | ||
"""Defines who to notify.""" | ||
self.ensure_one() | ||
company = self.employee_id.company_id | ||
if company.leave_notify_manager and self.employee_id.parent_id: | ||
return self.employee_id.parent_id | ||
return False | ||
|
||
@api.model | ||
def create(self, vals): | ||
res = super(HrHolidays, self).create(vals) | ||
res._notify_approvers() | ||
return res | ||
|
||
@api.multi | ||
def _notify_approvers(self): | ||
"""Input: res.user""" | ||
self.ensure_one() | ||
approvers = self._get_approvers_to_notify() | ||
if not approvers: | ||
return True | ||
for approver in approvers: | ||
self.add_follower(approver.id) | ||
if approver.user_id: | ||
self._message_auto_subscribe_notify( | ||
[approver.user_id.partner_id.id]) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = 'res.company' | ||
|
||
leave_notify_manager = fields.Boolean( | ||
string="Leave Requests notified to employee's manager", | ||
help="When a leave request is created the employee's manager " | ||
"will be added as follower and notified by email.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_hr_holiday_notify_employee_manager |
54 changes: 54 additions & 0 deletions
54
hr_holiday_notify_employee_manager/tests/test_hr_holiday_notify_employee_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp.tests.common import TransactionCase | ||
|
||
|
||
class TestNotifyEmployeeManager(TransactionCase): | ||
def setUp(self): | ||
super(TestNotifyEmployeeManager, self).setUp() | ||
self.hol_model = self.env['hr.holidays'] | ||
self.user_model = self.env['res.users'] | ||
self.emp_model = self.env['hr.employee'] | ||
self.type_model = self.env['hr.holidays.status'] | ||
|
||
self.user = self.user_model.create({ | ||
'name': 'Test User', | ||
'login': 'user', | ||
'email': 'test.user@example.com'}) | ||
self.manager = self.user_model.create({ | ||
'name': 'Test Manager', | ||
'login': 'manager', | ||
'email': 'test.manager@example.com'}) | ||
emp_manager = self.emp_model.create({ | ||
'name': 'Test Manager', | ||
'user_id': self.manager.id}) | ||
self.employee = self.emp_model.create({ | ||
'name': 'Test employee', | ||
'user_id': self.user.id, | ||
'parent_id': emp_manager.id}) | ||
self.holiday_type = self.type_model.create({'name': 'Leave'}) | ||
|
||
def test_add_follower(self): | ||
"""Tests if the employee's manager is added as follower to the leave | ||
request. | ||
""" | ||
manager = self.manager.partner_id | ||
# With the configuration disabled: | ||
self.employee.company_id.leave_notify_manager = False | ||
leave = self.hol_model.sudo(self.user).create({ | ||
'name': 'No-return-trip to Fiji', | ||
'holiday_status_id': self.holiday_type.id}) | ||
follower_set = manager in leave.message_follower_ids.mapped( | ||
'partner_id') if manager else False | ||
self.assertFalse(follower_set, "Follower added unexpectedly.") | ||
# With the configuration enabled: | ||
self.employee.company_id.leave_notify_manager = True | ||
leave = self.hol_model.sudo(self.user).create({ | ||
'name': 'No-return-trip to Bahamas', | ||
'holiday_status_id': self.holiday_type.id}) | ||
follower_set = manager in leave.message_follower_ids.mapped( | ||
'partner_id') if manager else False | ||
self.assertTrue(follower_set, "Employee's manager hasn't been added " | ||
"as follower.") |
17 changes: 17 additions & 0 deletions
17
hr_holiday_notify_employee_manager/views/res_company_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<odoo> | ||
|
||
<record id="view_company_form" model="ir.ui.view"> | ||
<field name="name">res.company - hr_holiday_notify_employee_manager</field> | ||
<field name="model">res.company</field> | ||
<field name="inherit_id" ref="base.view_company_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[@name='account_grp']" position="after"> | ||
<group name="hr_holidays" string="Leaves Management"> | ||
<field name="leave_notify_manager"/> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |