-
-
Notifications
You must be signed in to change notification settings - Fork 120
[17.0][ADD]mail_notify_employee_leave #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GuillermoNforgeflow
wants to merge
1
commit into
OCA:17.0
Choose a base branch
from
ForgeFlow:17.0-add-mail_noify_employee_leave
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,84 @@ | ||
| .. image:: https://odoo-community.org/readme-banner-image | ||
| :target: https://odoo-community.org/get-involved?utm_source=readme | ||
| :alt: Odoo Community Association | ||
|
|
||
| ========================== | ||
| Mail Notify Employee Leave | ||
| ========================== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:5f7b7a7481f72c60524273bb94fd697a975d3547b0b94c1f823902dfdaf99387 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
| :target: https://odoo-community.org/page/development-status | ||
| :alt: Beta | ||
| .. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License: AGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/mail/tree/17.0/mail_notify_employee_leave | ||
| :alt: OCA/mail | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/mail-17-0/mail-17-0-mail_notify_employee_leave | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=17.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This module automatically notifies users when they mention or assign a | ||
| colleague who is out of office. The notification includes the expected | ||
| return date of the absent user and is sent only once per day per user. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `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**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * ForgeFlow | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - `ForgeFlow <https://www.forgeflow.com>`__: | ||
|
|
||
| - Guillermo Navas <guillermo.navas@forgeflow.com> | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| 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. | ||
|
|
||
| This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/17.0/mail_notify_employee_leave>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or 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 @@ | ||
| from . import models |
This file contains hidden or 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 @@ | ||
| # Copyright 2026 ForgeFlow S.L. | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
|
||
| { | ||
| "name": "Mail Notify Employee Leave", | ||
| "summary": """ | ||
| Notifies users when they mention or assign someone who is out of office. | ||
| """, | ||
| "version": "17.0.1.0.0", | ||
| "license": "AGPL-3", | ||
| "author": "ForgeFlow, Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/mail", | ||
| "depends": ["mail", "hr_holidays"], | ||
| } |
This file contains hidden or 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,58 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * mail_notify_employee_leave | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 17.0+e\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "POT-Creation-Date: 2026-03-05 10:44+0000\n" | ||
| "PO-Revision-Date: 2026-03-05 10:44+0000\n" | ||
| "Last-Translator: \n" | ||
| "Language-Team: \n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: \n" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #. odoo-python | ||
| #: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 | ||
| #, python-format | ||
| msgid "%(name)s is out of office, expected back on %(date)s." | ||
| msgstr "%(name)s estará fuera de la oficina hasta el %(date)s." | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_date | ||
| msgid "Date of Last Absence Notification" | ||
| msgstr "Fecha de la última notificación" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_date | ||
| msgid "Date of the last notification record" | ||
| msgstr "Fecha del último registro de notificaciones" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model,name:mail_notify_employee_leave.model_mail_thread | ||
| msgid "Email Thread" | ||
| msgstr "Hilo de correo electrónico" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model,name:mail_notify_employee_leave.model_hr_employee | ||
| msgid "Employee" | ||
| msgstr "Empleado" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model,name:mail_notify_employee_leave.model_hr_leave | ||
| msgid "Time Off" | ||
| msgstr "Ausencias" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids | ||
| msgid "Users Notified Today" | ||
| msgstr "Usuarios notificados hoy" | ||
|
|
||
| #. module: mail_notify_employee_leave | ||
| #: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids | ||
| msgid "Users who have already been notified today about this absence" | ||
| msgstr "Usuarios que ya fueron notificados hoy sobre esta ausencia" |
This file contains hidden or 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,3 @@ | ||
| from . import mail_thread | ||
| from . import hr_leave | ||
| from . import hr_employee |
This file contains hidden or 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,19 @@ | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class HrEmployee(models.Model): | ||
| _inherit = "hr.employee" | ||
|
|
||
| absence_notified_user_ids = fields.Many2many( | ||
| "res.users", | ||
| string="Users Notified Today", | ||
| readonly=True, | ||
| copy=False, | ||
| help="Users who have already been notified today about this absence", | ||
| ) | ||
| absence_notified_date = fields.Date( | ||
| string="Date of Last Absence Notification", | ||
| readonly=True, | ||
| copy=False, | ||
| help="Date of the last notification record", | ||
| ) | ||
This file contains hidden or 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 @@ | ||
| from odoo import models | ||
|
|
||
|
|
||
| class HrLeave(models.Model): | ||
| _inherit = "hr.leave" | ||
|
|
||
| def _validate_leave_request(self): | ||
| """ | ||
| Override _validate_leave_request to skip absence notifications when | ||
| approving leaves. The context flag 'skip_absence_notification' prevents | ||
| _notify_thread from sending messages, | ||
| """ | ||
| if not self.env.context.get("skip_absence_notification"): | ||
| return super( | ||
| HrLeave, self.with_context(skip_absence_notification=True) | ||
| )._validate_leave_request() | ||
| return super()._validate_leave_request() |
This file contains hidden or 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,61 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from odoo import _, fields, models | ||
|
|
||
|
|
||
| class MailThread(models.AbstractModel): | ||
| _inherit = "mail.thread" | ||
|
|
||
| def _notify_thread(self, message, msg_vals=False, **kwargs): | ||
| """ | ||
| Alert the current user when a partner affected by the message is linked | ||
| is out of office. It ensures that each absent employee triggers only | ||
| one notification per user per day sending an internal message with the | ||
| employee's expected return date. | ||
| """ | ||
| recipients_data = super()._notify_thread(message, msg_vals=msg_vals, **kwargs) | ||
|
|
||
| if self.env.context.get("skip_absence_notification"): | ||
| return recipients_data | ||
|
|
||
| affected_partner_ids = msg_vals.get("partner_ids", []) if msg_vals else [] | ||
|
|
||
| today = fields.Date.today() | ||
|
|
||
| for partner_id in affected_partner_ids: | ||
| partner = self.env["res.partner"].browse(partner_id) | ||
| employee = self.env["hr.employee"].search( | ||
| [("user_id.partner_id", "=", partner.id)], limit=1 | ||
| ) | ||
| if employee and employee.is_absent: | ||
| if employee.absence_notified_date != today: | ||
| employee.absence_notified_user_ids = [(5, 0, 0)] | ||
| employee.absence_notified_date = today | ||
|
|
||
| if self.env.user not in employee.absence_notified_user_ids: | ||
| leave_date = fields.Date.from_string(employee.leave_date_to) | ||
| back_date = self.add_working_day(leave_date) | ||
| body = _( | ||
| "%(name)s is out of office, expected back on %(date)s." | ||
| ) % { | ||
| "name": employee.name, | ||
| "date": fields.Date.to_string(back_date), | ||
| } | ||
| self.message_notify( | ||
| partner_ids=[self.env.user.partner_id.id], | ||
| body=body, | ||
| subject="User out of office", | ||
| subtype_xmlid="mail.mt_note", | ||
| notify_author=True, | ||
| ) | ||
| employee.absence_notified_user_ids = [(4, self.env.user.id)] | ||
|
|
||
| return recipients_data | ||
|
|
||
| def add_working_day(self, date_obj): | ||
| next_day = date_obj + timedelta(days=1) | ||
| if next_day.weekday() == 5: | ||
| next_day += timedelta(days=2) | ||
| elif next_day.weekday() == 6: | ||
| next_day += timedelta(days=1) | ||
| return next_day |
This file contains hidden or 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,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or 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,2 @@ | ||
| - [ForgeFlow](https://www.forgeflow.com): | ||
| - Guillermo Navas \<<guillermo.navas@forgeflow.com>\> |
This file contains hidden or 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,3 @@ | ||
| This module automatically notifies users when they mention or assign | ||
| a colleague who is out of office. The notification includes the expected | ||
| return date of the absent user and is sent only once per day per user. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.