diff --git a/hr_holidays_natural_period_public/README.rst b/hr_holidays_natural_period_public/README.rst new file mode 100644 index 00000000..1d6f86df --- /dev/null +++ b/hr_holidays_natural_period_public/README.rst @@ -0,0 +1,93 @@ +============================== +Holidays Natural Period Public +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a6309313893a7739105b60c835b3de3c9c63cd15e1b32e18f5d90b0f78bcbffc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_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-16-0/hr-holidays-16-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=16.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 00000000..2afb07c8 --- /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 00000000..830d08ae --- /dev/null +++ b/hr_holidays_natural_period_public/__manifest__.py @@ -0,0 +1,17 @@ +# 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": "16.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_public", "hr_holidays_natural_period"], + "data": ["views/hr_leave_views.xml"], + "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 00000000..aeeec337 --- /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/models/__init__.py b/hr_holidays_natural_period_public/models/__init__.py new file mode 100644 index 00000000..9e77d1b0 --- /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 00000000..c9937f16 --- /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/readme/CONTRIBUTORS.rst b/hr_holidays_natural_period_public/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..d18d19ef --- /dev/null +++ b/hr_holidays_natural_period_public/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* `ForgeFlow `_: + * Laura Cazorla diff --git a/hr_holidays_natural_period_public/readme/DESCRIPTION.rst b/hr_holidays_natural_period_public/readme/DESCRIPTION.rst new file mode 100644 index 00000000..119c5ed4 --- /dev/null +++ b/hr_holidays_natural_period_public/readme/DESCRIPTION.rst @@ -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.rst b/hr_holidays_natural_period_public/readme/USAGE.rst new file mode 100644 index 00000000..45d09525 --- /dev/null +++ b/hr_holidays_natural_period_public/readme/USAGE.rst @@ -0,0 +1,7 @@ +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/index.html b/hr_holidays_natural_period_public/static/description/index.html new file mode 100644 index 00000000..77f2a75a --- /dev/null +++ b/hr_holidays_natural_period_public/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +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 00000000..c87f5d8f --- /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 00000000..2b014346 --- /dev/null +++ b/hr_holidays_natural_period_public/tests/test_hr_holidays_natural_period_public.py @@ -0,0 +1,190 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from freezegun import freeze_time + +from odoo import fields +from odoo.tests import Form, new_test_user +from odoo.tests.common import TransactionCase, users + + +@freeze_time("2023-01-01", tick=True) +class TestHrHolidaysNaturalPeriodPublic(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + ) + ) + cls.partner_model = cls.env["res.partner"] + cls.employee_model = cls.env["hr.employee"] + cls.public_holiday_model = cls.env["hr.holidays.public"] + + 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", + "type": "private", + "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_home_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="%s-12-31" % fields.Date.today().year, + ) + ) + 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["hr.holidays.public.line"].sudo()) + public_holiday_line.name = name + public_holiday_line.date = date + public_holiday_line.year_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.action_confirm() + leave_allocation.sudo().action_validate() + res_leave_type = self.env["hr.leave.type"].get_days_all_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"], "natural_day") + leave = self._create_hr_leave(self.leave_type, "2023-01-08", "2023-01-15") + self.assertEqual(leave.number_of_days, 8) + self.assertEqual(leave.number_of_days_display, 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.action_confirm() + 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"].get_days_all_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"], "natural_day") + 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) + self.assertEqual(leave.number_of_days_display, 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.action_confirm() + 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"].get_days_all_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"], "natural_day") + 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) + self.assertEqual(leave.number_of_days_display, 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.action_confirm() + 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"].get_days_all_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"], "natural_day") + 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) + self.assertEqual(leave.number_of_days_display, 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.action_confirm() + 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"].get_days_all_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"], "natural_day") + 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) + self.assertEqual(leave.number_of_days_display, 7) diff --git a/hr_holidays_natural_period_public/views/hr_leave_views.xml b/hr_holidays_natural_period_public/views/hr_leave_views.xml new file mode 100644 index 00000000..cc20860d --- /dev/null +++ b/hr_holidays_natural_period_public/views/hr_leave_views.xml @@ -0,0 +1,27 @@ + + + + + hr.leave.view.form + hr.leave + + + + {'invisible': [('leave_type_request_unit', 'in', ['day', 'natural_day'])]} + + + {'readonly': [('state', 'not in', ('draft', 'confirm'))], 'invisible': [('leave_type_request_unit', 'in', ['day', 'natural_day'])]} + + + {'invisible': [('leave_type_request_unit', 'in', ['day', 'natural_day'])]} + + + + + diff --git a/setup/hr_holidays_natural_period_public/odoo/addons/hr_holidays_natural_period_public b/setup/hr_holidays_natural_period_public/odoo/addons/hr_holidays_natural_period_public new file mode 120000 index 00000000..a5e6c588 --- /dev/null +++ b/setup/hr_holidays_natural_period_public/odoo/addons/hr_holidays_natural_period_public @@ -0,0 +1 @@ +../../../../hr_holidays_natural_period_public \ No newline at end of file diff --git a/setup/hr_holidays_natural_period_public/setup.py b/setup/hr_holidays_natural_period_public/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/hr_holidays_natural_period_public/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)