Skip to content

Commit a07e0f3

Browse files
author
GuillermoNforgeflow
committed
[ADD]mail_notify_employee_leave
1 parent f752a76 commit a07e0f3

File tree

11 files changed

+625
-0
lines changed

11 files changed

+625
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
==========================
6+
Mail Notify Employee Leave
7+
==========================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:5f7b7a7481f72c60524273bb94fd697a975d3547b0b94c1f823902dfdaf99387
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
22+
:alt: License: AGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
24+
:target: https://github.com/OCA/mail/tree/17.0/mail_notify_employee_leave
25+
:alt: OCA/mail
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/mail-17-0/mail-17-0-mail_notify_employee_leave
28+
:alt: Translate me on Weblate
29+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=17.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
This module automatically notifies users when they mention or assign a
36+
colleague who is out of office. The notification includes the expected
37+
return date of the absent user and is sent only once per day per user.
38+
39+
**Table of contents**
40+
41+
.. contents::
42+
:local:
43+
44+
Bug Tracker
45+
===========
46+
47+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
48+
In case of trouble, please check there if your issue has already been reported.
49+
If you spotted it first, help us to smash it by providing a detailed and welcomed
50+
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_notify_employee_leave%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
52+
Do not contact contributors directly about support or help with technical issues.
53+
54+
Credits
55+
=======
56+
57+
Authors
58+
-------
59+
60+
* ForgeFlow
61+
62+
Contributors
63+
------------
64+
65+
- `ForgeFlow <https://www.forgeflow.com>`__:
66+
67+
- Guillermo Navas <guillermo.navas@forgeflow.com>
68+
69+
Maintainers
70+
-----------
71+
72+
This module is maintained by the OCA.
73+
74+
.. image:: https://odoo-community.org/logo.png
75+
:alt: Odoo Community Association
76+
:target: https://odoo-community.org
77+
78+
OCA, or the Odoo Community Association, is a nonprofit organization whose
79+
mission is to support the collaborative development of Odoo features and
80+
promote its widespread use.
81+
82+
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/17.0/mail_notify_employee_leave>`_ project on GitHub.
83+
84+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2026 ForgeFlow S.L.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "Mail Notify Employee Leave",
6+
"summary": """
7+
Notifies users when they mention or assign someone who is out of office.
8+
""",
9+
"version": "17.0.1.0.0",
10+
"license": "AGPL-3",
11+
"author": "ForgeFlow, Odoo Community Association (OCA)",
12+
"website": "https://github.com/OCA/mail",
13+
"depends": ["mail", "hr_holidays"],
14+
"data": [
15+
"security/ir.model.access.csv",
16+
],
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import mail_thread
2+
from . import user_absence_notification
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from odoo import fields, models
2+
3+
4+
class MailThread(models.AbstractModel):
5+
_inherit = "mail.thread"
6+
7+
def _notify_thread(self, message, msg_vals=False, **kwargs):
8+
"""
9+
Alert the current user when a partner affected by the message is linked
10+
is out of office. It ensures that each absent employee triggers only
11+
one notification per user per day by recording notifications in
12+
'user.absence.notification' and sending an internal message with the
13+
employee's expected return date.
14+
"""
15+
recipients_data = super()._notify_thread(message, msg_vals=msg_vals, **kwargs)
16+
17+
affected_partner_ids = msg_vals.get("partner_ids", []) if msg_vals else []
18+
19+
for partner_id in affected_partner_ids:
20+
partner = self.env["res.partner"].browse(partner_id)
21+
employee = self.env["hr.employee"].search(
22+
[("user_id.partner_id", "=", partner.id)], limit=1
23+
)
24+
if employee and employee.is_absent:
25+
today = fields.Date.today()
26+
already_notified = self.env["user.absence.notification"].search(
27+
[
28+
("absent_user_id", "=", employee.id),
29+
("notified_user_id", "=", self.env.user.id),
30+
("date", "=", today),
31+
]
32+
)
33+
if already_notified:
34+
continue
35+
36+
self.env["user.absence.notification"].create(
37+
{
38+
"absent_user_id": employee.id,
39+
"notified_user_id": self.env.user.id,
40+
"date": today,
41+
}
42+
)
43+
body = (
44+
f"{employee.name} is out of office, expected "
45+
f"back on {employee.leave_date_to}."
46+
)
47+
self.message_notify(
48+
partner_ids=[self.env.user.partner_id.id],
49+
body=body,
50+
subject="User out of office",
51+
subtype_xmlid="mail.mt_note",
52+
notify_author=True,
53+
)
54+
55+
return recipients_data
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from odoo import fields, models
2+
3+
4+
class UserAbsenceNotification(models.Model):
5+
"""
6+
This model stores daily records of absence notifications sent to users.
7+
It ensures that each user receives only one notification per absent
8+
employee per day.
9+
Fields:
10+
- absent_user_id: the employee who is currently out of office
11+
- notified_user_id: the user who received the notification
12+
- date: the date the notification was sent
13+
"""
14+
15+
_name = "user.absence.notification"
16+
_description = "Track daily absence notifications"
17+
18+
absent_user_id = fields.Many2one("hr.employee", string="Absent User", required=True)
19+
notified_user_id = fields.Many2one(
20+
"res.users", string="Notified User", required=True
21+
)
22+
date = fields.Date(string="Fecha", required=True)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [ForgeFlow](https://www.forgeflow.com):
2+
- Guillermo Navas \<<guillermo.navas@forgeflow.com>\>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module automatically notifies users when they mention or assign
2+
a colleague who is out of office. The notification includes the expected
3+
return date of the absent user and is sent only once per day per user.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_user_absence_notification,User absence notifications,model_user_absence_notification,base.group_user,1,1,1,0

0 commit comments

Comments
 (0)