diff --git a/hr_holidays_natural_period_public/README.rst b/hr_holidays_natural_period_public/README.rst new file mode 100644 index 000000000..44468576f --- /dev/null +++ b/hr_holidays_natural_period_public/README.rst @@ -0,0 +1,94 @@ +============================== +Holidays Natural Period Public +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d7117c649058f3ef3237f0ad1a5e94984dd27f0b9def5b076560602358b268a8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/hr_holidays_natural_period_public + :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-18-0/hr-holidays-18-0-hr_holidays_natural_period_public + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This is a glue module between HR Holidays Public and HR Holidays Natural +Period modules. + +It allows the user to decide whether public holidays should be excluded +from leave days computation or not, when the requested leave type uses +natural days as the request unit. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To choose whether you want to exclude public holidays from leave days +computation, you can access the settings of the leave type and check or +uncheck the box "Exclude public holidays". Also make sure that the +"Request Unit" is set to "Natural Day". + +To access the settings of the leave type, you must navigate to Time Off +--> Configurations --> Time Off Types and select the desired leave type. + +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 `__: + + - Laura Cazorla + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_holidays_natural_period_public/__init__.py b/hr_holidays_natural_period_public/__init__.py new file mode 100644 index 000000000..2afb07c8e --- /dev/null +++ b/hr_holidays_natural_period_public/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/hr_holidays_natural_period_public/__manifest__.py b/hr_holidays_natural_period_public/__manifest__.py new file mode 100644 index 000000000..fc7bdef0e --- /dev/null +++ b/hr_holidays_natural_period_public/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Holidays Natural Period Public", + "summary": "Allow excluding public holidays for natural days holidays", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "category": "Human Resources", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr-holidays", + "depends": ["hr_holidays_natural_period", "hr_holidays_public"], + "demo": ["demo/hr_leave_type_data.xml"], + "installable": True, + "application": False, +} diff --git a/hr_holidays_natural_period_public/demo/hr_leave_type_data.xml b/hr_holidays_natural_period_public/demo/hr_leave_type_data.xml new file mode 100644 index 000000000..aeeec3372 --- /dev/null +++ b/hr_holidays_natural_period_public/demo/hr_leave_type_data.xml @@ -0,0 +1,9 @@ + + + + False + + diff --git a/hr_holidays_natural_period_public/i18n/gl_ES.po b/hr_holidays_natural_period_public/i18n/gl_ES.po new file mode 100644 index 000000000..6a2059201 --- /dev/null +++ b/hr_holidays_natural_period_public/i18n/gl_ES.po @@ -0,0 +1,20 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_natural_period_public +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: gl_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: hr_holidays_natural_period_public +#: model:ir.model,name:hr_holidays_natural_period_public.model_resource_calendar +msgid "Resource Working Time" +msgstr "" diff --git a/hr_holidays_natural_period_public/i18n/hr_holidays_natural_period_public.pot b/hr_holidays_natural_period_public/i18n/hr_holidays_natural_period_public.pot new file mode 100644 index 000000000..53aed4cea --- /dev/null +++ b/hr_holidays_natural_period_public/i18n/hr_holidays_natural_period_public.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_natural_period_public +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_natural_period_public +#: model:ir.model,name:hr_holidays_natural_period_public.model_resource_calendar +msgid "Resource Working Time" +msgstr "" diff --git a/hr_holidays_natural_period_public/i18n/it.po b/hr_holidays_natural_period_public/i18n/it.po new file mode 100644 index 000000000..1fe54a1c2 --- /dev/null +++ b/hr_holidays_natural_period_public/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_natural_period_public +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-11-21 11:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: hr_holidays_natural_period_public +#: model:ir.model,name:hr_holidays_natural_period_public.model_resource_calendar +msgid "Resource Working Time" +msgstr "Orario lavoro risorsa" diff --git a/hr_holidays_natural_period_public/models/__init__.py b/hr_holidays_natural_period_public/models/__init__.py new file mode 100644 index 000000000..9e77d1b05 --- /dev/null +++ b/hr_holidays_natural_period_public/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import resource_calendar diff --git a/hr_holidays_natural_period_public/models/resource_calendar.py b/hr_holidays_natural_period_public/models/resource_calendar.py new file mode 100644 index 000000000..c9937f167 --- /dev/null +++ b/hr_holidays_natural_period_public/models/resource_calendar.py @@ -0,0 +1,20 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ResourceCalendar(models.Model): + _inherit = "resource.calendar" + + def _attendance_intervals_batch( + self, start_dt, end_dt, resources=None, domain=None, tz=None + ): + result = super()._attendance_intervals_batch( + start_dt, end_dt, resources=resources, domain=domain, tz=tz + ) + if self.env.context.get("exclude_public_holidays") and resources: + return self._attendance_intervals_batch_exclude_public_holidays( + start_dt, end_dt, result, resources, tz + ) + return result diff --git a/hr_holidays_natural_period_public/pyproject.toml b/hr_holidays_natural_period_public/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_holidays_natural_period_public/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_holidays_natural_period_public/readme/CONTRIBUTORS.md b/hr_holidays_natural_period_public/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..f06c6a52b --- /dev/null +++ b/hr_holidays_natural_period_public/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://forgeflow.com): + - Laura Cazorla \ diff --git a/hr_holidays_natural_period_public/readme/DESCRIPTION.md b/hr_holidays_natural_period_public/readme/DESCRIPTION.md new file mode 100644 index 000000000..8eedf1fc6 --- /dev/null +++ b/hr_holidays_natural_period_public/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This is a glue module between HR Holidays Public and HR Holidays Natural +Period modules. + +It allows the user to decide whether public holidays should be excluded +from leave days computation or not, when the requested leave type uses +natural days as the request unit. diff --git a/hr_holidays_natural_period_public/readme/USAGE.md b/hr_holidays_natural_period_public/readme/USAGE.md new file mode 100644 index 000000000..d2f7a61e0 --- /dev/null +++ b/hr_holidays_natural_period_public/readme/USAGE.md @@ -0,0 +1,8 @@ +To choose whether you want to exclude public holidays from leave days +computation, you can access the settings of the leave type and check or +uncheck the box "Exclude public holidays". Also make sure that the +"Request Unit" is set to "Natural Day". + +To access the settings of the leave type, you must navigate to Time Off +--\> Configurations --\> Time Off Types and select the desired leave +type. diff --git a/hr_holidays_natural_period_public/static/description/icon.png b/hr_holidays_natural_period_public/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/hr_holidays_natural_period_public/static/description/icon.png differ diff --git a/hr_holidays_natural_period_public/static/description/index.html b/hr_holidays_natural_period_public/static/description/index.html new file mode 100644 index 000000000..8f5a02809 --- /dev/null +++ b/hr_holidays_natural_period_public/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Holidays Natural Period Public + + + +
+

Holidays Natural Period Public

+ + +

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

+

This is a glue module between HR Holidays Public and HR Holidays Natural +Period modules.

+

It allows the user to decide whether public holidays should be excluded +from leave days computation or not, when the requested leave type uses +natural days as the request unit.

+

Table of contents

+ +
+

Usage

+

To choose whether you want to exclude public holidays from leave days +computation, you can access the settings of the leave type and check or +uncheck the box “Exclude public holidays”. Also make sure that the +“Request Unit” is set to “Natural Day”.

+

To access the settings of the leave type, you must navigate to Time Off +–> Configurations –> Time Off Types and select the desired leave type.

+
+
+

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

+

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

+
+
+
+ + diff --git a/hr_holidays_natural_period_public/tests/__init__.py b/hr_holidays_natural_period_public/tests/__init__.py new file mode 100644 index 000000000..c87f5d8f6 --- /dev/null +++ b/hr_holidays_natural_period_public/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_hr_holidays_natural_period_public diff --git a/hr_holidays_natural_period_public/tests/test_hr_holidays_natural_period_public.py b/hr_holidays_natural_period_public/tests/test_hr_holidays_natural_period_public.py new file mode 100644 index 000000000..2675d276c --- /dev/null +++ b/hr_holidays_natural_period_public/tests/test_hr_holidays_natural_period_public.py @@ -0,0 +1,183 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# Copyright 2025 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests import Form, new_test_user +from odoo.tests.common import users + +from odoo.addons.base.tests.common import BaseCommon + + +class TestHrHolidaysNaturalPeriodPublic(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner_model = cls.env["res.partner"] + cls.employee_model = cls.env["hr.employee"] + cls.public_holiday_model = cls.env["calendar.public.holiday"] + cls.leave_type = cls.env.ref( + "hr_holidays_natural_period.hr_leave_type_natural_day_test" + ) + cls.leave_type_day = cls.env.ref("hr_holidays.holiday_status_cl") + cls.leave_type_day.employee_requests = "yes" + calendar = cls.env.ref("resource.resource_calendar_std") + calendar = calendar.copy({"name": "Test calendar"}) + calendar.switch_calendar_type() + calendar.attendance_ids.filtered( + lambda x: x.week_type == "0" + and not x.display_type + and x.day_period == "afternoon" + ).unlink() + calendar.attendance_ids.filtered( + lambda x: x.week_type == "1" + and not x.display_type + and x.day_period == "morning" + ).unlink() + partner = cls.partner_model.create( + { + "name": "Test employee", + "country_id": cls.env.ref("base.es").id, + } + ) + cls.user = new_test_user(cls.env, login="test-user") + cls.employee = cls.employee_model.create( + { + "name": "Test employee", + "address_id": partner.id, + "resource_calendar_id": calendar.id, + "user_id": cls.user.id, + } + ) + cls.public_holiday = cls.public_holiday_model.create( + { + "year": 2023, + "country_id": False, + } + ) + + def _create_leave_allocation(self, leave_type, days): + leave_allocation_form = Form( + self.env["hr.leave.allocation"].with_context( + default_date_from="2023-01-01", + default_date_to=f"{fields.Date.today().year}-12-31", + ) + ) + leave_allocation_form.name = "TEST" + leave_allocation_form.holiday_status_id = leave_type + leave_allocation_form.number_of_days_display = days + return leave_allocation_form.save() + + def _create_hr_leave(self, leave_type, date_from, date_to): + leave_form = Form(self.env["hr.leave"]) + leave_form.holiday_status_id = leave_type + leave_form.request_date_from = date_from + leave_form.request_date_to = date_to + return leave_form.save() + + def _create_public_holiday_line(self, name, date, year): + public_holiday_line = Form(self.env["calendar.public.holiday.line"].sudo()) + public_holiday_line.name = name + public_holiday_line.date = date + public_holiday_line.public_holiday_id = year + return public_holiday_line.save() + + @users("test-user") + def test_hr_leave_natural_day(self): + leave_allocation = self._create_leave_allocation(self.leave_type, 10) + leave_allocation.sudo().action_validate() + res_leave_type = ( + self.env["hr.leave.type"] + .with_company(self.env.company) + .get_allocation_data_request()[0][1] + ) + self.assertEqual(res_leave_type["remaining_leaves"], 10) + self.assertEqual(res_leave_type["virtual_remaining_leaves"], 10) + self.assertEqual(res_leave_type["max_leaves"], 10) + self.assertEqual(res_leave_type["leaves_taken"], 0) + self.assertEqual(res_leave_type["virtual_leaves_taken"], 0) + self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit) + leave = self._create_hr_leave(self.leave_type, "2023-01-08", "2023-01-15") + self.assertEqual(leave.number_of_days, 8) + + @users("test-user") + def test_hr_leave_natural_day_public_holiday_01(self): + leave_allocation = self._create_leave_allocation(self.leave_type, 10) + leave_allocation.sudo().action_validate() + self._create_public_holiday_line("P1", "2023-01-09", self.public_holiday) + res_leave_type = ( + self.env["hr.leave.type"] + .with_company(self.env.company) + .get_allocation_data_request()[0][1] + ) + self.assertEqual(res_leave_type["remaining_leaves"], 10) + self.assertEqual(res_leave_type["virtual_remaining_leaves"], 10) + self.assertEqual(res_leave_type["max_leaves"], 10) + self.assertEqual(res_leave_type["leaves_taken"], 0) + self.assertEqual(res_leave_type["virtual_leaves_taken"], 0) + self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit) + self.assertEqual(self.leave_type.exclude_public_holidays, False) + leave = self._create_hr_leave(self.leave_type, "2023-01-08", "2023-01-15") + self.assertEqual(leave.number_of_days, 8) + + @users("test-user") + def test_hr_leave_natural_day_public_holiday_02(self): + leave_allocation = self._create_leave_allocation(self.leave_type, 10) + leave_allocation.sudo().action_validate() + self._create_public_holiday_line("P1", "2023-01-09", self.public_holiday) + self.leave_type.write({"exclude_public_holidays": True}) + res_leave_type = ( + self.env["hr.leave.type"] + .with_company(self.env.company) + .get_allocation_data_request()[0][1] + ) + self.assertEqual(res_leave_type["remaining_leaves"], 10) + self.assertEqual(res_leave_type["virtual_remaining_leaves"], 10) + self.assertEqual(res_leave_type["max_leaves"], 10) + self.assertEqual(res_leave_type["leaves_taken"], 0) + self.assertEqual(res_leave_type["virtual_leaves_taken"], 0) + self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit) + self.assertEqual(self.leave_type.exclude_public_holidays, True) + leave = self._create_hr_leave(self.leave_type, "2023-01-08", "2023-01-15") + self.assertEqual(leave.number_of_days, 7) + + @users("test-user") + def test_hr_leave_natural_day_public_holiday_weekend_01(self): + leave_allocation = self._create_leave_allocation(self.leave_type, 10) + leave_allocation.sudo().action_validate() + self._create_public_holiday_line("P1", "2023-01-14", self.public_holiday) + res_leave_type = ( + self.env["hr.leave.type"] + .with_company(self.env.company) + .get_allocation_data_request()[0][1] + ) + self.assertEqual(res_leave_type["remaining_leaves"], 10) + self.assertEqual(res_leave_type["virtual_remaining_leaves"], 10) + self.assertEqual(res_leave_type["max_leaves"], 10) + self.assertEqual(res_leave_type["leaves_taken"], 0) + self.assertEqual(res_leave_type["virtual_leaves_taken"], 0) + self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit) + self.assertEqual(self.leave_type.exclude_public_holidays, False) + leave = self._create_hr_leave(self.leave_type, "2023-01-08", "2023-01-15") + self.assertEqual(leave.number_of_days, 8) + + @users("test-user") + def test_hr_leave_natural_day_public_holiday_weekend_02(self): + leave_allocation = self._create_leave_allocation(self.leave_type, 10) + leave_allocation.sudo().action_validate() + self._create_public_holiday_line("P1", "2023-01-14", self.public_holiday) + self.leave_type.write({"exclude_public_holidays": True}) + res_leave_type = ( + self.env["hr.leave.type"] + .with_company(self.env.company) + .get_allocation_data_request()[0][1] + ) + self.assertEqual(res_leave_type["remaining_leaves"], 10) + self.assertEqual(res_leave_type["virtual_remaining_leaves"], 10) + self.assertEqual(res_leave_type["max_leaves"], 10) + self.assertEqual(res_leave_type["leaves_taken"], 0) + self.assertEqual(res_leave_type["virtual_leaves_taken"], 0) + self.assertEqual(res_leave_type["request_unit"], self.leave_type.request_unit) + self.assertEqual(self.leave_type.exclude_public_holidays, True) + leave = self._create_hr_leave(self.leave_type, "2023-01-08", "2023-01-15") + self.assertEqual(leave.number_of_days, 7)