From 3072e23fe0a0f8cbaf30181680eafde5f9d73d8a Mon Sep 17 00:00:00 2001 From: GuillermoNforgeflow Date: Tue, 30 Jun 2026 09:15:57 +0200 Subject: [PATCH] [ADD]resource_calendar_season --- resource_calendar_season/README.rst | 96 ++++ resource_calendar_season/__init__.py | 1 + resource_calendar_season/__manifest__.py | 16 + resource_calendar_season/i18n/es.po | 226 +++++++++ resource_calendar_season/models/__init__.py | 2 + .../models/resource_calendar.py | 112 +++++ .../models/resource_calendar_season.py | 71 +++ resource_calendar_season/pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 2 + .../readme/DESCRIPTION.md | 8 + resource_calendar_season/readme/USAGE.md | 6 + .../security/ir.model.access.csv | 3 + .../static/description/index.html | 442 ++++++++++++++++++ resource_calendar_season/tests/__init__.py | 1 + .../tests/test_resource_calendar_season.py | 109 +++++ .../views/resource_calendar_views.xml | 39 ++ 16 files changed, 1137 insertions(+) create mode 100644 resource_calendar_season/README.rst create mode 100644 resource_calendar_season/__init__.py create mode 100644 resource_calendar_season/__manifest__.py create mode 100644 resource_calendar_season/i18n/es.po create mode 100644 resource_calendar_season/models/__init__.py create mode 100644 resource_calendar_season/models/resource_calendar.py create mode 100644 resource_calendar_season/models/resource_calendar_season.py create mode 100644 resource_calendar_season/pyproject.toml create mode 100644 resource_calendar_season/readme/CONTRIBUTORS.md create mode 100644 resource_calendar_season/readme/DESCRIPTION.md create mode 100644 resource_calendar_season/readme/USAGE.md create mode 100644 resource_calendar_season/security/ir.model.access.csv create mode 100644 resource_calendar_season/static/description/index.html create mode 100644 resource_calendar_season/tests/__init__.py create mode 100644 resource_calendar_season/tests/test_resource_calendar_season.py create mode 100644 resource_calendar_season/views/resource_calendar_views.xml diff --git a/resource_calendar_season/README.rst b/resource_calendar_season/README.rst new file mode 100644 index 00000000000..fdf9c9568c5 --- /dev/null +++ b/resource_calendar_season/README.rst @@ -0,0 +1,96 @@ +======================== +Resource Calendar Season +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4d6a3cdf13ff4eb21c2f7410076545c5c25943c2164303780d93a6929966c7ce + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-lightgray.png?logo=github + :target: https://github.com/OCA/hr/tree/17.0/resource_calendar_season + :alt: OCA/hr +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-17-0/hr-17-0-resource_calendar_season + :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&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module lets a single working time (``resource.calendar``) behave +differently depending on the time of the year, using **recurring** +seasons defined by month, so they repeat automatically every year. + +A *seasonal* calendar holds no working hours of its own. For each date +it delegates the working-time computation to the calendar of the season +that matches that date, falling back to a configurable default working +time for any date not covered by a season. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Assign the seasonal working time wherever a calendar is used (an +employee's contract, the company, etc.). + +From then on, any computation based on that calendar (worked hours, +planned days, lead times...) automatically uses the working time of the +season matching each date, and the default working time for uncovered +dates. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ForgeFlow + +Contributors +------------ + +- ForgeFlow + + - Guillermo Navas + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/resource_calendar_season/__init__.py b/resource_calendar_season/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/resource_calendar_season/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/resource_calendar_season/__manifest__.py b/resource_calendar_season/__manifest__.py new file mode 100644 index 00000000000..741d87b3467 --- /dev/null +++ b/resource_calendar_season/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Resource Calendar Season", + "summary": "Recurring seasonal working times for a resource calendar", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "category": "Human Resources", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr", + "depends": ["resource"], + "data": [ + "security/ir.model.access.csv", + "views/resource_calendar_views.xml", + ], +} diff --git a/resource_calendar_season/i18n/es.po b/resource_calendar_season/i18n/es.po new file mode 100644 index 00000000000..af77b0ced11 --- /dev/null +++ b/resource_calendar_season/i18n/es.po @@ -0,0 +1,226 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * resource_calendar_season +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-06-30 06:36+0000\n" +"PO-Revision-Date: 2026-06-30 06:36+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: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__4 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__4 +msgid "April" +msgstr "Abril" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__8 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__8 +msgid "August" +msgstr "Agosto" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__create_uid +msgid "Created by" +msgstr "" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__create_date +msgid "Created on" +msgstr "" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__12 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__12 +msgid "December" +msgstr "Diciembre" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar__default_calendar_id +msgid "Default Working Time" +msgstr "Horario de trabajo por defecto" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__2 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__2 +msgid "February" +msgstr "Febrero" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__month_from +msgid "From Month" +msgstr "Mes inicial" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__id +msgid "ID" +msgstr "" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__1 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__1 +msgid "January" +msgstr "Enero" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__7 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__7 +msgid "July" +msgstr "Julio" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__6 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__6 +msgid "June" +msgstr "Junio" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__write_date +msgid "Last Updated on" +msgstr "" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__3 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__3 +msgid "March" +msgstr "Marzo" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__5 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__5 +msgid "May" +msgstr "Mayo" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__name +msgid "Name" +msgstr "Nombre" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__11 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__11 +msgid "November" +msgstr "Noviembre" + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__10 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__10 +msgid "October" +msgstr "Octubre" + +#. module: resource_calendar_season +#: model:ir.model,name:resource_calendar_season.model_resource_calendar_season +msgid "Resource Calendar Season" +msgstr "Temporada de calendario de recursos" + +#. module: resource_calendar_season +#: model:ir.model,name:resource_calendar_season.model_resource_calendar +msgid "Resource Working Time" +msgstr "Tiempo de trabajo de recursos" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar__is_seasonal +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__calendar_id +msgid "Seasonal Calendar" +msgstr "Calendario estacional" + +#. module: resource_calendar_season +#. odoo-python +#: code:addons/resource_calendar_season/models/resource_calendar.py:0 +#, python-format +msgid "" +"Seasonal calendar %(name)s cannot use itself as the default working time." +msgstr "" +"El calendario estacional %(name)s no puede usarse a sí mismo como horario de " +"trabajo por defecto." + +#. module: resource_calendar_season +#. odoo-python +#: code:addons/resource_calendar_season/models/resource_calendar.py:0 +#, python-format +msgid "Seasonal calendar %(name)s requires a default working time." +msgstr "El calendario estacional %(name)s requiere un horario de trabajo por defecto." + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar__season_ids +#: model_terms:ir.ui.view,arch_db:resource_calendar_season.resource_calendar_form +msgid "Seasons" +msgstr "Temporadas" + +#. module: resource_calendar_season +#. odoo-python +#: code:addons/resource_calendar_season/models/resource_calendar_season.py:0 +#, python-format +msgid "Seasons %(first)s and %(second)s overlap." +msgstr "Las temporadas %(first)s y %(second)s se solapan." + +#. module: resource_calendar_season +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_from__9 +#: model:ir.model.fields.selection,name:resource_calendar_season.selection__resource_calendar_season__month_to__9 +msgid "September" +msgstr "Septiembre" + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__sequence +msgid "Sequence" +msgstr "Secuencia" + +#. module: resource_calendar_season +#. odoo-python +#: code:addons/resource_calendar_season/models/resource_calendar.py:0 +#, python-format +msgid "" +"The default working time of %(name)s cannot itself be a seasonal calendar." +msgstr "" +"El horario por defecto de %(name)s no puede ser a su vez un calendario " +"estacional." + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__month_to +msgid "To Month" +msgstr "Mes final" + +#. module: resource_calendar_season +#: model:ir.model.fields,help:resource_calendar_season.field_resource_calendar__is_seasonal +msgid "" +"When enabled, this calendar has no working hours of its own. Instead, the " +"working time is taken from the season matching each date, falling back to " +"the default working time for uncovered dates." +msgstr "" +"Cuando está activado, este calendario no tiene horas de trabajo propias. En " +"su lugar, el horario de trabajo se toma de la temporada que corresponde a cada " +"fecha, recurriendo al horario de trabajo por defecto para las fechas no " +"cubiertas." + +#. module: resource_calendar_season +#: model:ir.model.fields,field_description:resource_calendar_season.field_resource_calendar_season__season_calendar_id +msgid "Working Time" +msgstr "Horario de trabajo" + +#. module: resource_calendar_season +#: model:ir.model.fields,help:resource_calendar_season.field_resource_calendar_season__season_calendar_id +msgid "Working time applied during this season." +msgstr "Horario de trabajo aplicado durante esta temporada." + +#. module: resource_calendar_season +#: model:ir.model.fields,help:resource_calendar_season.field_resource_calendar__default_calendar_id +msgid "Working time applied on dates not covered by any season." +msgstr "Horario de trabajo aplicado en las fechas no cubiertas por ninguna temporada." diff --git a/resource_calendar_season/models/__init__.py b/resource_calendar_season/models/__init__.py new file mode 100644 index 00000000000..27f852c0ccd --- /dev/null +++ b/resource_calendar_season/models/__init__.py @@ -0,0 +1,2 @@ +from . import resource_calendar_season +from . import resource_calendar diff --git a/resource_calendar_season/models/resource_calendar.py b/resource_calendar_season/models/resource_calendar.py new file mode 100644 index 00000000000..ad551f567e1 --- /dev/null +++ b/resource_calendar_season/models/resource_calendar.py @@ -0,0 +1,112 @@ +from datetime import datetime, time, timedelta + +from pytz import timezone + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ResourceCalendar(models.Model): + _inherit = "resource.calendar" + + is_seasonal = fields.Boolean( + string="Seasonal Calendar", + help="When enabled, this calendar has no working hours of its own. " + "Instead, the working time is taken from the season matching each date, " + "falling back to the default working time for uncovered dates.", + ) + season_ids = fields.One2many( + comodel_name="resource.calendar.season", + inverse_name="calendar_id", + string="Seasons", + ) + default_calendar_id = fields.Many2one( + comodel_name="resource.calendar", + string="Default Working Time", + ondelete="restrict", + help="Working time applied on dates not covered by any season.", + ) + + @api.constrains("is_seasonal", "default_calendar_id") + def _check_seasonal(self): + for calendar in self: + if not calendar.is_seasonal: + continue + if not calendar.default_calendar_id: + raise ValidationError( + _( + "Seasonal calendar %(name)s requires a default working time.", + name=calendar.name, + ) + ) + if calendar.default_calendar_id.is_seasonal: + raise ValidationError( + _( + "The default working time of %(name)s cannot itself be a " + "seasonal calendar.", + name=calendar.name, + ) + ) + if calendar.default_calendar_id == calendar: + raise ValidationError( + _( + "Seasonal calendar %(name)s cannot use itself as the default " + "working time.", + name=calendar.name, + ) + ) + + def _get_season_calendar(self, day): + self.ensure_one() + season = self.season_ids.filtered(lambda s: s._contains_date(day))[:1] + return season.season_calendar_id or self.default_calendar_id + + def _split_periods_by_season(self, start_dt, end_dt): + """Split ``[start_dt, end_dt]`` into consecutive sub-periods, each + mapped to the working-time calendar that applies for its dates.""" + self.ensure_one() + cal_tz = timezone(self.tz or "UTC") + start_local = start_dt.astimezone(cal_tz) + end_local = end_dt.astimezone(cal_tz) + periods = [] + segment_start = start_dt + segment_calendar = self._get_season_calendar(start_local.date()) + day = start_local.date() + timedelta(days=1) + last_day = end_local.date() + while day <= last_day: + calendar = self._get_season_calendar(day) + if calendar != segment_calendar: + boundary = cal_tz.localize(datetime.combine(day, time.min)).astimezone( + start_dt.tzinfo + ) + if boundary > segment_start: + periods.append((segment_start, boundary, segment_calendar)) + segment_start = boundary + segment_calendar = calendar + day += timedelta(days=1) + periods.append((segment_start, end_dt, segment_calendar)) + return periods + + def _attendance_intervals_batch( + self, start_dt, end_dt, resources=None, domain=None, tz=None, lunch=False + ): + self.ensure_one() + if not self.is_seasonal: + return super()._attendance_intervals_batch( + start_dt, end_dt, resources, domain, tz, lunch + ) + combined = {} + for period_start, period_end, calendar in self._split_periods_by_season( + start_dt, end_dt + ): + if not calendar: + continue + sub_result = calendar._attendance_intervals_batch( + period_start, period_end, resources, domain, tz, lunch + ) + for resource_id, intervals in sub_result.items(): + if resource_id in combined: + combined[resource_id] = combined[resource_id] | intervals + else: + combined[resource_id] = intervals + return combined diff --git a/resource_calendar_season/models/resource_calendar_season.py b/resource_calendar_season/models/resource_calendar_season.py new file mode 100644 index 00000000000..584db72b223 --- /dev/null +++ b/resource_calendar_season/models/resource_calendar_season.py @@ -0,0 +1,71 @@ +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + +MONTHS = [ + ("1", "January"), + ("2", "February"), + ("3", "March"), + ("4", "April"), + ("5", "May"), + ("6", "June"), + ("7", "July"), + ("8", "August"), + ("9", "September"), + ("10", "October"), + ("11", "November"), + ("12", "December"), +] + + +class ResourceCalendarSeason(models.Model): + _name = "resource.calendar.season" + _description = "Resource Calendar Season" + _order = "sequence" + + name = fields.Char(required=True) + sequence = fields.Integer(default=10) + calendar_id = fields.Many2one( + comodel_name="resource.calendar", + string="Seasonal Calendar", + required=True, + ondelete="cascade", + ) + season_calendar_id = fields.Many2one( + comodel_name="resource.calendar", + string="Working Time", + required=True, + ondelete="restrict", + help="Working time applied during this season.", + ) + month_from = fields.Selection(MONTHS, string="From Month", required=True) + month_to = fields.Selection(MONTHS, string="To Month", required=True) + + @api.constrains("month_from", "month_to", "calendar_id") + def _check_no_overlap(self): + for calendar in self.mapped("calendar_id"): + coverage = {} + for season in calendar.season_ids: + for month in season._covered_months(): + if month in coverage: + raise ValidationError( + _( + "Seasons %(first)s and %(second)s overlap.", + first=coverage[month].name, + second=season.name, + ) + ) + coverage[month] = season + + def _covered_months(self): + """Return the set of month numbers covered by the season, handling + ranges that wrap around the year end (e.g. December to January).""" + self.ensure_one() + start = int(self.month_from) + end = int(self.month_to) + if start <= end: + return set(range(start, end + 1)) + return set(range(start, 13)) | set(range(1, end + 1)) + + def _contains_date(self, day): + self.ensure_one() + return day.month in self._covered_months() diff --git a/resource_calendar_season/pyproject.toml b/resource_calendar_season/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/resource_calendar_season/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/resource_calendar_season/readme/CONTRIBUTORS.md b/resource_calendar_season/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..728261cb123 --- /dev/null +++ b/resource_calendar_season/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- ForgeFlow + - Guillermo Navas \<\> diff --git a/resource_calendar_season/readme/DESCRIPTION.md b/resource_calendar_season/readme/DESCRIPTION.md new file mode 100644 index 00000000000..6c5ec552cc8 --- /dev/null +++ b/resource_calendar_season/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module lets a single working time (`resource.calendar`) behave differently +depending on the time of the year, using **recurring** seasons defined by month, +so they repeat automatically every year. + +A *seasonal* calendar holds no working hours of its own. For each date it +delegates the working-time computation to the calendar of the season that +matches that date, falling back to a configurable default working time for any +date not covered by a season. \ No newline at end of file diff --git a/resource_calendar_season/readme/USAGE.md b/resource_calendar_season/readme/USAGE.md new file mode 100644 index 00000000000..00ba3d6f54e --- /dev/null +++ b/resource_calendar_season/readme/USAGE.md @@ -0,0 +1,6 @@ +Assign the seasonal working time wherever a calendar is used (an employee's +contract, the company, etc.). + +From then on, any computation based on that calendar (worked hours, planned +days, lead times...) automatically uses the working time of the season matching +each date, and the default working time for uncovered dates. \ No newline at end of file diff --git a/resource_calendar_season/security/ir.model.access.csv b/resource_calendar_season/security/ir.model.access.csv new file mode 100644 index 00000000000..f932487c6da --- /dev/null +++ b/resource_calendar_season/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_resource_calendar_season_user,resource.calendar.season user,model_resource_calendar_season,base.group_user,1,0,0,0 +access_resource_calendar_season_manager,resource.calendar.season manager,model_resource_calendar_season,base.group_system,1,1,1,1 diff --git a/resource_calendar_season/static/description/index.html b/resource_calendar_season/static/description/index.html new file mode 100644 index 00000000000..ae0685b4ad2 --- /dev/null +++ b/resource_calendar_season/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Resource Calendar Season + + + +
+

Resource Calendar Season

+ + +

Beta License: AGPL-3 OCA/hr Translate me on Weblate Try me on Runboat

+

This module lets a single working time (resource.calendar) behave +differently depending on the time of the year, using recurring +seasons defined by month, so they repeat automatically every year.

+

A seasonal calendar holds no working hours of its own. For each date +it delegates the working-time computation to the calendar of the season +that matches that date, falling back to a configurable default working +time for any date not covered by a season.

+

Table of contents

+ +
+

Usage

+

Assign the seasonal working time wherever a calendar is used (an +employee’s contract, the company, etc.).

+

From then on, any computation based on that calendar (worked hours, +planned days, lead times…) automatically uses the working time of the +season matching each date, and the default working time for uncovered +dates.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/resource_calendar_season/tests/__init__.py b/resource_calendar_season/tests/__init__.py new file mode 100644 index 00000000000..38bb6d50787 --- /dev/null +++ b/resource_calendar_season/tests/__init__.py @@ -0,0 +1 @@ +from . import test_resource_calendar_season diff --git a/resource_calendar_season/tests/test_resource_calendar_season.py b/resource_calendar_season/tests/test_resource_calendar_season.py new file mode 100644 index 00000000000..b1f07b2e677 --- /dev/null +++ b/resource_calendar_season/tests/test_resource_calendar_season.py @@ -0,0 +1,109 @@ +from datetime import datetime + +from pytz import utc + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestResourceCalendarSeason(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ResourceCalendar = cls.env["resource.calendar"] + cls.standard = cls._create_calendar("Standard 40h", 8.0, 16.0) + cls.summer = cls._create_calendar("Summer 35h", 8.0, 15.0) + cls.seasonal = cls.ResourceCalendar.create( + { + "name": "Seasonal", + "tz": "UTC", + "is_seasonal": True, + "default_calendar_id": cls.standard.id, + "season_ids": [ + ( + 0, + 0, + { + "name": "Summer", + "season_calendar_id": cls.summer.id, + "month_from": "6", + "month_to": "9", + }, + ), + ], + } + ) + + @classmethod + def _create_calendar(cls, name, hour_from, hour_to): + return cls.ResourceCalendar.create( + { + "name": name, + "tz": "UTC", + "attendance_ids": [ + ( + 0, + 0, + { + "name": f"{dayofweek}-{name}", + "dayofweek": str(dayofweek), + "hour_from": hour_from, + "hour_to": hour_to, + "day_period": "morning", + }, + ) + for dayofweek in range(5) + ], + } + ) + + def _hours(self, start, end): + return self.seasonal.get_work_hours_count( + utc.localize(start), utc.localize(end), compute_leaves=False + ) + + def test_winter_week_uses_default(self): + hours = self._hours(datetime(2026, 1, 5), datetime(2026, 1, 10)) + self.assertEqual(hours, 40.0) + + def test_summer_week_uses_season(self): + hours = self._hours(datetime(2026, 7, 6), datetime(2026, 7, 11)) + self.assertEqual(hours, 35.0) + + def test_range_crossing_boundary_sums_each_season(self): + # Week of 2026-09-28: Mon-Wed (28-30 Sep) summer 7h, Thu/Fri (1-2 Oct) std 8h + hours = self._hours(datetime(2026, 9, 28), datetime(2026, 10, 3)) + self.assertEqual(hours, 7.0 * 3 + 8.0 * 2) + + def test_season_calendar_resolution(self): + self.assertEqual( + self.seasonal._get_season_calendar(datetime(2026, 7, 1).date()), + self.summer, + ) + self.assertEqual( + self.seasonal._get_season_calendar(datetime(2026, 12, 1).date()), + self.standard, + ) + + def test_overlapping_seasons_raise(self): + with self.assertRaises(ValidationError): + self.seasonal.write( + { + "season_ids": [ + ( + 0, + 0, + { + "name": "Overlap", + "season_calendar_id": self.summer.id, + "month_from": "9", + "month_to": "10", + }, + ), + ] + } + ) + + def test_seasonal_requires_default(self): + with self.assertRaises(ValidationError): + self.ResourceCalendar.create({"name": "Bad seasonal", "is_seasonal": True}) diff --git a/resource_calendar_season/views/resource_calendar_views.xml b/resource_calendar_season/views/resource_calendar_views.xml new file mode 100644 index 00000000000..2701504b20f --- /dev/null +++ b/resource_calendar_season/views/resource_calendar_views.xml @@ -0,0 +1,39 @@ + + + + resource.calendar.form - resource_calendar_season + resource.calendar + + + + + + + is_seasonal + + + + + + + + + + + + + + + + + + + +