diff --git a/hr_holidays_approval_split/README.rst b/hr_holidays_approval_split/README.rst new file mode 100644 index 000000000..de2c47723 --- /dev/null +++ b/hr_holidays_approval_split/README.rst @@ -0,0 +1,92 @@ +======================= +Time Off Approval Split +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7c25656dd529c1d0649bd3ed106831090c04f8e8dee7e83c0f420977219b59b5 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/17.0/hr_holidays_approval_split + :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-17-0/hr-holidays-17-0-hr_holidays_approval_split + :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=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module introduces a new field validation_type_split in Time Off +Types to define whether approval is required for hour-based requests, +day-based requests, or both. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. create a Time Off request using a Time Off Type that requires + validation by an Officer. +2. Depending on the value selected in the Approval Type field, the + system will determine whether approval is required for hour-based or + day-based requests. +3. If the request type does not require approval according to this + configuration, the leave will be automatically confirmed and + validated. + +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-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_approval_split/__init__.py b/hr_holidays_approval_split/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/hr_holidays_approval_split/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_holidays_approval_split/__manifest__.py b/hr_holidays_approval_split/__manifest__.py new file mode 100644 index 000000000..04167549f --- /dev/null +++ b/hr_holidays_approval_split/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Time Off Approval Split", + "summary": """ + Allow configuring approval requirements separately for hour-based and + day-based time off requests. + """, + "category": "Human Resources/Time Off", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr-holidays", + "contributors": [ + "Guillermo Navas ", + ], + "depends": ["hr_holidays"], + "data": [ + "views/hr_leave_type_views.xml", + ], +} diff --git a/hr_holidays_approval_split/models/__init__.py b/hr_holidays_approval_split/models/__init__.py new file mode 100644 index 000000000..7c444ff5b --- /dev/null +++ b/hr_holidays_approval_split/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_leave_type +from . import hr_leave diff --git a/hr_holidays_approval_split/models/hr_leave.py b/hr_holidays_approval_split/models/hr_leave.py new file mode 100644 index 000000000..adac6e48a --- /dev/null +++ b/hr_holidays_approval_split/models/hr_leave.py @@ -0,0 +1,41 @@ +from odoo import _, api, models + + +class HolidaysRequest(models.Model): + _inherit = "hr.leave" + + @api.model_create_multi + def create(self, vals_list): + holidays = super().create(vals_list) + + auto_validate = holidays.filtered( + lambda h: ( + h.holiday_status_id.leave_validation_type != "no_validation" + and ( + ( + h.holiday_status_id.validation_type_split == "hours" + and not h.request_unit_hours + and not h.request_unit_half + ) + or ( + h.holiday_status_id.validation_type_split == "days" + and (h.request_unit_hours or h.request_unit_half) + ) + ) + ) + ) + + for holiday in auto_validate: + # As done in core, we use sudo() as the user might not have the + # rights when creating the leave + # https://github.com/odoo/odoo/blob/97b60952d59a57aba12b048cb4da4f41d85d2ea2/addons/hr_holidays/models/hr_leave.py#L978-L980 + holiday.sudo().action_validate() + holiday.sudo().message_subscribe( + partner_ids=holiday._get_responsible_for_approval().partner_id.ids + ) + holiday.sudo().message_post( + body=_("The time off has been automatically approved"), + subtype_xmlid="mail.mt_comment", + ) + + return holidays diff --git a/hr_holidays_approval_split/models/hr_leave_type.py b/hr_holidays_approval_split/models/hr_leave_type.py new file mode 100644 index 000000000..d0790fd5b --- /dev/null +++ b/hr_holidays_approval_split/models/hr_leave_type.py @@ -0,0 +1,19 @@ +from odoo import fields, models + + +class HrLeaveType(models.Model): + _inherit = "hr.leave.type" + + validation_type_split = fields.Selection( + [ + ("both", "Hours and Days require approval"), + ("hours", "Only Hours require approval"), + ("days", "Only Days require approval"), + ], + string="Approval Type", + default="both", + help=""" + Define whether approval is required for hour-based requests, + day-based requests or both. + """, + ) diff --git a/hr_holidays_approval_split/pyproject.toml b/hr_holidays_approval_split/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_holidays_approval_split/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_holidays_approval_split/readme/CONTRIBUTORS.md b/hr_holidays_approval_split/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..2f1465d02 --- /dev/null +++ b/hr_holidays_approval_split/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://www.forgeflow.com): + - Guillermo Navas \<\> diff --git a/hr_holidays_approval_split/readme/DESCRIPTION.md b/hr_holidays_approval_split/readme/DESCRIPTION.md new file mode 100644 index 000000000..9785be763 --- /dev/null +++ b/hr_holidays_approval_split/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module introduces a new field validation_type_split in Time Off Types +to define whether approval is required for hour-based requests, day-based +requests, or both. \ No newline at end of file diff --git a/hr_holidays_approval_split/readme/USAGE.md b/hr_holidays_approval_split/readme/USAGE.md new file mode 100644 index 000000000..5ecea4731 --- /dev/null +++ b/hr_holidays_approval_split/readme/USAGE.md @@ -0,0 +1,5 @@ +1. create a Time Off request using a Time Off Type that requires validation by an Officer. +2. Depending on the value selected in the Approval Type field, the system will determine +whether approval is required for hour-based or day-based requests. +3. If the request type does not require approval according to this configuration, the leave +will be automatically confirmed and validated. \ No newline at end of file diff --git a/hr_holidays_approval_split/static/description/index.html b/hr_holidays_approval_split/static/description/index.html new file mode 100644 index 000000000..a31bbda7e --- /dev/null +++ b/hr_holidays_approval_split/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Time Off Approval Split + + + +
+

Time Off Approval Split

+ + +

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

+

This module introduces a new field validation_type_split in Time Off +Types to define whether approval is required for hour-based requests, +day-based requests, or both.

+

Table of contents

+ +
+

Usage

+
    +
  1. create a Time Off request using a Time Off Type that requires +validation by an Officer.
  2. +
  3. Depending on the value selected in the Approval Type field, the +system will determine whether approval is required for hour-based or +day-based requests.
  4. +
  5. If the request type does not require approval according to this +configuration, the leave will be automatically confirmed and +validated.
  6. +
+
+
+

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_approval_split/tests/__init__.py b/hr_holidays_approval_split/tests/__init__.py new file mode 100644 index 000000000..7dd682c73 --- /dev/null +++ b/hr_holidays_approval_split/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_holidays_approvals diff --git a/hr_holidays_approval_split/tests/test_hr_holidays_approvals.py b/hr_holidays_approval_split/tests/test_hr_holidays_approvals.py new file mode 100644 index 000000000..bd0780031 --- /dev/null +++ b/hr_holidays_approval_split/tests/test_hr_holidays_approvals.py @@ -0,0 +1,96 @@ +# Copyright 2026 ForgeFlow S.L. +# (http://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import datetime + +from odoo.tests.common import TransactionCase + + +class TestHolidaysApprovals(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.employee = cls.env["hr.employee"].create( + { + "name": "Test Employee", + } + ) + + cls.leave_hours = cls.env["hr.leave.type"].create( + { + "name": "Hours Approval", + "leave_validation_type": "hr", + "validation_type_split": "hours", + "request_unit": "hour", + "requires_allocation": "no", + } + ) + + cls.leave_days = cls.env["hr.leave.type"].create( + { + "name": "Days Approval", + "leave_validation_type": "hr", + "validation_type_split": "days", + "request_unit": "hour", + "requires_allocation": "no", + } + ) + + cls.leave_no_validation = cls.env["hr.leave.type"].create( + { + "name": "No Approval", + "leave_validation_type": "no_validation", + "request_unit": "day", + "requires_allocation": "no", + } + ) + + def _create_leave(self, leave_type, date_from, date_to, request_hours=False): + return self.env["hr.leave"].create( + { + "employee_id": self.employee.id, + "holiday_status_id": leave_type.id, + "request_date_from": date_from, + "request_date_to": date_to, + "request_unit_hours": request_hours, + "request_unit_half": False, + } + ) + + def test_hours_request_requires_approval_when_hours_type(self): + leave = self._create_leave( + self.leave_hours, + datetime(2026, 3, 25, 8, 0), + datetime(2026, 3, 25, 10, 0), + request_hours=True, + ) + self.assertEqual(leave.state, "confirm") + + def test_days_request_auto_validated_when_hours_type(self): + leave = self._create_leave( + self.leave_hours, + datetime(2026, 3, 25), + datetime(2026, 3, 26), + request_hours=False, + ) + self.assertEqual(leave.state, "validate") + + def test_days_request_requires_approval_when_days_type(self): + leave = self._create_leave( + self.leave_days, + datetime(2026, 3, 25), + datetime(2026, 3, 26), + request_hours=False, + ) + self.assertEqual(leave.state, "confirm") + + def test_no_validation_type_is_always_validated(self): + leave = self._create_leave( + self.leave_no_validation, + datetime(2026, 3, 25), + datetime(2026, 3, 26), + request_hours=False, + ) + self.assertEqual(leave.state, "validate") diff --git a/hr_holidays_approval_split/views/hr_leave_type_views.xml b/hr_holidays_approval_split/views/hr_leave_type_views.xml new file mode 100644 index 000000000..38eb2e580 --- /dev/null +++ b/hr_holidays_approval_split/views/hr_leave_type_views.xml @@ -0,0 +1,16 @@ + + + + hr.leave.type.form.new.approval.field + hr.leave.type + + + + + + + +