-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by etobella
- Loading branch information
Showing
20 changed files
with
928 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,87 @@ | ||
======================= | ||
Hr Holidays Auto Extend | ||
======================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:00afe160865b13f5c2f5f4032e011cd1bb43e32a86dfbe8c57308679759017b8 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/licence-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%2Fhr--holidays-lightgray.png?logo=github | ||
:target: https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_auto_extend | ||
:alt: OCA/hr-holidays | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/hr-holidays-16-0/hr-holidays-16-0-hr_holidays_auto_extend | ||
: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/hr-holidays&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
With this module, we will be able to extend automatically a leave when the period is reached. | ||
|
||
This might be necessary for leaves without a clear return date for the employee. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
* Access leave types and mark it as "Auto extendable" | ||
* When the manager approves the leave, the "Auto extendable" check will be marked | ||
* When we decide that the leave is no longer extendable, we can uncheck it. | ||
* | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-holidays/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/hr-holidays/issues/new?body=module:%20hr_holidays_auto_extend%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* CreuBlanca | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Enric Tobella | ||
* | ||
|
||
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/hr-holidays <https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_auto_extend>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 @@ | ||
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,22 @@ | ||
# Copyright 2023 CreuBlanca | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Hr Holidays Auto Extend", | ||
"summary": """ | ||
Allow to extend some kind of holidays""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "CreuBlanca,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/hr-holidays", | ||
"depends": [ | ||
"hr_holidays", | ||
], | ||
"data": [ | ||
"views/hr_leave.xml", | ||
"views/hr_leave_type.xml", | ||
"data/cron.xml", | ||
"data/mail.xml", | ||
], | ||
"demo": [], | ||
} |
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo noupdate="1"> | ||
<record model="ir.cron" id="auto_extend_cron"> | ||
<field name="name">Holidays: Auto extend</field> | ||
<field name="user_id" ref="base.user_root" /> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">days</field> | ||
<field name="numbercall">-1</field> | ||
<field name="model_id" ref="model_hr_leave" /> | ||
<field name="state">code</field> | ||
<field name="code">model._cron_auto_extend()</field> | ||
</record> | ||
</odoo> |
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo noupdate="1"> | ||
<record id="mail_activity_error_auto_extend" model="mail.activity.type"> | ||
<field name="name">Leave cannot be extended due to overlapping</field> | ||
<field name="summary">note</field> | ||
<field name="category">default</field> | ||
<field name="res_model">hr.leave</field> | ||
<field name="icon">fa-tasks</field> | ||
<field name="delay_count">0</field> | ||
</record> | ||
</odoo> |
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,76 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * hr_holidays_auto_extend | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.0\n" | ||
"Report-Msgid-Bugs-To: \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: hr_holidays_auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave__auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave_type__auto_extend | ||
msgid "Auto Extend" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave__auto_extend_period | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave_type__auto_extend_period | ||
msgid "Auto Extend Period" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave__auto_extend_type | ||
msgid "Auto extend type" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave__display_name | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave_type__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.actions.server,name:hr_holidays_auto_extend.auto_extend_cron_ir_actions_server | ||
#: model:ir.cron,cron_name:hr_holidays_auto_extend.auto_extend_cron | ||
#: model:ir.cron,name:hr_holidays_auto_extend.auto_extend_cron | ||
msgid "Holidays: Auto extend" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave__id | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave_type__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave____last_update | ||
#: model:ir.model.fields,field_description:hr_holidays_auto_extend.field_hr_leave_type____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:mail.activity.type,name:hr_holidays_auto_extend.mail_activity_error_auto_extend | ||
msgid "Leave cannot be extended due to overlapping" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model,name:hr_holidays_auto_extend.model_hr_leave | ||
msgid "Time Off" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:ir.model,name:hr_holidays_auto_extend.model_hr_leave_type | ||
msgid "Time Off Type" | ||
msgstr "" | ||
|
||
#. module: hr_holidays_auto_extend | ||
#: model:mail.activity.type,summary:hr_holidays_auto_extend.mail_activity_error_auto_extend | ||
msgid "note" | ||
msgstr "" |
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,2 @@ | ||
from . import hr_leave_type | ||
from . import hr_leave |
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,79 @@ | ||
# Copyright 2023 CreuBlanca | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from datetime import timedelta | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class HrLeave(models.Model): | ||
_inherit = "hr.leave" | ||
|
||
auto_extend_type = fields.Boolean( | ||
related="holiday_status_id.auto_extend", string="Auto extend type" | ||
) | ||
auto_extend = fields.Boolean( | ||
compute="_compute_auto_extend", store=True, readonly=False | ||
) | ||
auto_extend_period = fields.Integer( | ||
compute="_compute_auto_extend", store=True, readonly=False | ||
) | ||
|
||
def _check_date_state(self): | ||
if not self.env.context.get("__no_check_state_date"): | ||
super()._check_date_state() | ||
return | ||
|
||
def _get_number_of_days(self, date_from, date_to, employee_id): | ||
"""Returns a float equals to the timedelta between two dates given as string. | ||
We need to modify in order to add the compute_leaves = False | ||
""" | ||
if not self.env.context.get("__no_check_state_date") or not employee_id: | ||
return super()._get_number_of_days(date_from, date_to, employee_id) | ||
employee = self.env["hr.employee"].browse(employee_id) | ||
return employee._get_work_days_data_batch( | ||
date_from, date_to, compute_leaves=False | ||
)[employee.id] | ||
|
||
@api.depends("holiday_status_id") | ||
def _compute_auto_extend(self): | ||
for record in self: | ||
record.auto_extend = record.holiday_status_id.auto_extend | ||
record.auto_extend_period = record.holiday_status_id.auto_extend_period | ||
|
||
def _cron_auto_extend_domain(self): | ||
return [ | ||
("request_date_to", "<=", fields.Date.today()), | ||
("auto_extend", "=", True), | ||
("auto_extend_period", ">", 0), | ||
("state", "=", "validate"), | ||
] | ||
|
||
def _cron_auto_extend(self): | ||
leaves = self.search(self._cron_auto_extend_domain()) | ||
for leave in leaves.with_context(__no_check_state_date=True): | ||
request_date_to = leave.request_date_to + timedelta( | ||
days=leave.auto_extend_period | ||
) | ||
domain = [ | ||
("date_from", "<", request_date_to), | ||
("date_from", ">", leave.date_from), | ||
("employee_id", "=", leave.employee_id.id), | ||
("id", "!=", leave.id), | ||
("state", "not in", ["cancel", "refuse"]), | ||
] | ||
if self.search(domain, limit=1): | ||
leave.auto_extend = False | ||
leave.activity_schedule( | ||
"hr_holidays_auto_extend.mail_activity_error_auto_extend", | ||
) | ||
continue | ||
vals = {"request_date_to": request_date_to} | ||
vals.update( | ||
leave.onchange(vals, ["request_date_to"], leave._onchange_spec())[ | ||
"value" | ||
] | ||
) | ||
leave.write(vals) | ||
leave._remove_resource_leave() | ||
leave._create_resource_leave() |
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,11 @@ | ||
# Copyright 2023 CreuBlanca | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class HrLeaveType(models.Model): | ||
_inherit = "hr.leave.type" | ||
|
||
auto_extend = fields.Boolean() | ||
auto_extend_period = fields.Integer(default=7) |
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,2 @@ | ||
* Enric Tobella | ||
* |
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,3 @@ | ||
With this module, we will be able to extend automatically a leave when the period is reached. | ||
|
||
This might be necessary for leaves without a clear return date for the employee. |
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,4 @@ | ||
* Access leave types and mark it as "Auto extendable" | ||
* When the manager approves the leave, the "Auto extendable" check will be marked | ||
* When we decide that the leave is no longer extendable, we can uncheck it. | ||
* |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.