Skip to content

Commit

Permalink
[MIG] hr_holidays_leave_repeated: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-filament committed Dec 26, 2024
1 parent 927bd44 commit 9b3072c
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 125 deletions.
12 changes: 7 additions & 5 deletions hr_holidays_leave_repeated/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ HR Holidays leave repeated
: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/14.0/hr_holidays_leave_repeated
:target: https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_leave_repeated
: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-14-0/hr-holidays-14-0-hr_holidays_leave_repeated
:target: https://translation.odoo-community.org/projects/hr-holidays-16-0/hr-holidays-16-0-hr_holidays_leave_repeated
: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=14.0
: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|
Expand All @@ -48,13 +48,15 @@ Usage
#. Alternatively set the 'Repeat Mode' field to 'End Date', then set 'Repeat Every' and 'Repeat End Date'.
#. Create (save) the leave request. All the periodical leave requests are automatically created.

Note for HR Time Off responsibles : creating repeated leaves can only be used when selecting Mode = "By Employee" and that all selected employees should share the same resource calendar, otherwise an error is raised.

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_leave_repeated%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_leave_repeated%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.

Expand Down Expand Up @@ -86,6 +88,6 @@ 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/14.0/hr_holidays_leave_repeated>`_ project on GitHub.
This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_leave_repeated>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_holidays_leave_repeated/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Onestein, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-holidays",
"category": "Human Resources",
"version": "14.0.1.1.0",
"version": "16.0.1.1.0",
"license": "AGPL-3",
"depends": ["hr_holidays"],
"data": ["views/hr_leave_type.xml", "views/hr_leave.xml"],
Expand Down
14 changes: 4 additions & 10 deletions hr_holidays_leave_repeated/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ msgstr "Veuillez définir un nombre de répétitions positif."
#: model:ir.model.fields,field_description:hr_holidays_leave_repeated.field_hr_leave__holiday_type_repeat
#: model:ir.model.fields,field_description:hr_holidays_leave_repeated.field_hr_leave_type__repeat
msgid "Repeat"
msgstr "Répeter"
msgstr "Répéter"

#. module: hr_holidays_leave_repeated
#: model:ir.model.fields,field_description:hr_holidays_leave_repeated.field_hr_leave__repeat_limit
Expand All @@ -84,7 +84,7 @@ msgstr "Répéter # fois"
#. module: hr_holidays_leave_repeated
#: model:ir.model.fields,field_description:hr_holidays_leave_repeated.field_hr_leave__repeat_end_date
msgid "Repeat End Date"
msgstr "Répéter la date de fin"
msgstr "Date de fin de répétition"

#. module: hr_holidays_leave_repeated
#: model:ir.model.fields,field_description:hr_holidays_leave_repeated.field_hr_leave__repeat_every
Expand Down Expand Up @@ -145,15 +145,9 @@ msgstr ""
#. module: hr_holidays_leave_repeated
#: model:ir.model,name:hr_holidays_leave_repeated.model_hr_leave
msgid "Time Off"
msgstr ""
msgstr "Congés"

#. module: hr_holidays_leave_repeated
#: model:ir.model,name:hr_holidays_leave_repeated.model_hr_leave_type
msgid "Time Off Type"
msgstr ""

#~ msgid "Leave"
#~ msgstr "Congé"

#~ msgid "Leave Type"
#~ msgstr "Type de congé"
msgstr "Type de congés"
10 changes: 2 additions & 8 deletions hr_holidays_leave_repeated/i18n/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,9 @@ msgstr ""
#. module: hr_holidays_leave_repeated
#: model:ir.model,name:hr_holidays_leave_repeated.model_hr_leave
msgid "Time Off"
msgstr ""
msgstr "Verlof"

#. module: hr_holidays_leave_repeated
#: model:ir.model,name:hr_holidays_leave_repeated.model_hr_leave_type
msgid "Time Off Type"
msgstr ""

#~ msgid "Leave"
#~ msgstr "Verlof"

#~ msgid "Leave Type"
#~ msgstr "Verlofsoort"
msgstr "Verlofsoort"
75 changes: 51 additions & 24 deletions hr_holidays_leave_repeated/models/hr_leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,30 @@ class HrLeave(models.Model):
repeat_end_date = fields.Date(default=lambda self: fields.Date.today())

@api.model
def _update_repeated_workday_dates(self, employee, from_dt, to_dt, days):
def _update_repeated_workday_dates(self, resource_calendar, from_dt, to_dt, days):
user = self.env.user
calendar = employee.resource_calendar_id
orig_from_dt = fields.Datetime.context_timestamp(user, from_dt)
orig_to_dt = fields.Datetime.context_timestamp(user, to_dt)
work_hours = calendar.get_work_hours_count(from_dt, to_dt, compute_leaves=False)
work_hours = resource_calendar.get_work_hours_count(
from_dt, to_dt, compute_leaves=False
)
while work_hours:
from_dt = from_dt + relativedelta(days=days)
to_dt = to_dt + relativedelta(days=days)

new_work_hours = calendar.get_work_hours_count(
user_from_dt = fields.Datetime.context_timestamp(user, from_dt)
user_to_dt = fields.Datetime.context_timestamp(user, to_dt)
from_dt = from_dt - user_from_dt.tzinfo._utcoffset
from_dt = from_dt + orig_from_dt.tzinfo._utcoffset
to_dt = to_dt - user_to_dt.tzinfo._utcoffset
to_dt = to_dt + orig_to_dt.tzinfo._utcoffset

new_work_hours = resource_calendar.get_work_hours_count(
from_dt, to_dt, compute_leaves=True
)
if new_work_hours and work_hours <= new_work_hours:
break

user_from_dt = fields.Datetime.context_timestamp(user, from_dt)
user_to_dt = fields.Datetime.context_timestamp(user, to_dt)
from_dt = from_dt - user_from_dt.tzinfo._utcoffset
from_dt = from_dt + orig_from_dt.tzinfo._utcoffset
to_dt = to_dt - user_to_dt.tzinfo._utcoffset
to_dt = to_dt + orig_to_dt.tzinfo._utcoffset

return from_dt, to_dt

@api.model
Expand Down Expand Up @@ -85,7 +86,7 @@ def _get_repeated_vals_dict(self):
}

@api.model
def _update_repeated_leave_vals(self, vals, employee):
def _update_repeated_leave_vals(self, vals, resource_calendar):
vals_dict = self._get_repeated_vals_dict()
param_dict = vals_dict[vals.get("repeat_every")]
from_dt = fields.Datetime.from_string(vals.get("date_from"))
Expand All @@ -96,7 +97,7 @@ def _update_repeated_leave_vals(self, vals, employee):
raise UserError(param_dict["user_error_msg"])

from_dt, to_dt = self._update_repeated_workday_dates(
employee, from_dt, to_dt, param_dict["days"]
resource_calendar, from_dt, to_dt, param_dict["days"]
)

vals["request_date_from"] = vals["date_from"] = from_dt
Expand All @@ -105,7 +106,7 @@ def _update_repeated_leave_vals(self, vals, employee):
return vals

@api.model
def create_repeated_handler(self, vals, employee):
def create_repeated_handler(self, vals, resource_calendar):
def _check_repeating(count, vals):
repeat_mode = vals.get("repeat_mode", "times")
if repeat_mode == "times" and count < vals.get("repeat_limit", 0):
Expand All @@ -116,21 +117,47 @@ def _check_repeating(count, vals):
return False

count = 1
vals = self._update_repeated_leave_vals(vals, employee)
vals = self._update_repeated_leave_vals(vals, resource_calendar)
while _check_repeating(count, vals):
self.with_context(skip_create_handler=True).create(vals)
count += 1
vals = self._update_repeated_leave_vals(vals, employee)
vals = self._update_repeated_leave_vals(vals, resource_calendar)

@api.model
def create(self, vals):
res = super().create(vals)
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
skip_create_handler = self.env.context.get("skip_create_handler")
all_vals_set = vals.get("repeat_every") and vals.get("repeat_mode")
if not skip_create_handler and all_vals_set:
employee = self.env["hr.employee"].browse(vals.get("employee_id"))
if employee.resource_calendar_id:
self.create_repeated_handler(vals, employee)
for vals in vals_list:
all_vals_set = (
vals.get("repeat_every")
and vals.get("repeat_mode")
and vals.get("holiday_type") == "employee"
)
if not skip_create_handler and all_vals_set:
employees = self.env["hr.employee"]
if vals.get("employee_id"):
employees = self.env["hr.employee"].browse(vals.get("employee_id"))
elif vals.get("employee_ids"):
employees = self.env["hr.employee"].browse(
vals.get("employee_ids")[0][2]
)
resource_calendars = employees.mapped("resource_calendar_id")
if len(resource_calendars) == 1:
self.create_repeated_handler(vals, resource_calendars[0])
elif len(resource_calendars) == 0:
raise ValidationError(

Check warning on line 148 in hr_holidays_leave_repeated/models/hr_leave.py

View check run for this annotation

Codecov / codecov/patch

hr_holidays_leave_repeated/models/hr_leave.py#L148

Added line #L148 was not covered by tests
_(
"Please define resource calendar on employee(s) in order "
"to compute repeated leaves."
)
)
else:
raise ValidationError(
_(
"Creating leaves for multiple employees with different "
"resource calendar is not supported."
)
)
return res

@api.constrains("repeat_limit", "repeat_end_date")
Expand Down
2 changes: 2 additions & 0 deletions hr_holidays_leave_repeated/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
#. Set the 'Repeat Mode' field to 'Number of Times'. Set the proper values for 'Repeat Every' and 'Repeat # times'.
#. Alternatively set the 'Repeat Mode' field to 'End Date', then set 'Repeat Every' and 'Repeat End Date'.
#. Create (save) the leave request. All the periodical leave requests are automatically created.

Note for HR Time Off responsibles : creating repeated leaves can only be used when selecting Mode = "By Employee" and that all selected employees should share the same resource calendar, otherwise an error is raised.
18 changes: 11 additions & 7 deletions hr_holidays_leave_repeated/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">HR Holidays leave repeated</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:162d88dbd2fd8cd12cd7f1c32c31e6e97c12d2bdd59120e9a955f2f49248efd1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/14.0/hr_holidays_leave_repeated"><img alt="OCA/hr-holidays" src="https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-holidays-14-0/hr-holidays-14-0-hr_holidays_leave_repeated"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_leave_repeated"><img alt="OCA/hr-holidays" src="https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-holidays-16-0/hr-holidays-16-0-hr_holidays_leave_repeated"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to create periodical leaves.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -398,13 +399,14 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<li>Alternatively set the ‘Repeat Mode’ field to ‘End Date’, then set ‘Repeat Every’ and ‘Repeat End Date’.</li>
<li>Create (save) the leave request. All the periodical leave requests are automatically created.</li>
</ol>
<p>Note for HR Time Off responsibles : creating repeated leaves can only be used when selecting Mode = “By Employee” and that all selected employees should share the same resource calendar, otherwise an error is raised.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr-holidays/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_leave_repeated%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_leave_repeated%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -426,11 +428,13 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-holidays/tree/14.0/hr_holidays_leave_repeated">OCA/hr-holidays</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_leave_repeated">OCA/hr-holidays</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 9b3072c

Please sign in to comment.