Skip to content

Commit

Permalink
[FIX] hr_holidays_public: calendar.get_work_hours_count
Browse files Browse the repository at this point in the history
Allow to call get_work_hours_count on resource.calendar taking care
of public holidays
  • Loading branch information
petrus-v committed Sep 17, 2024
1 parent e0098c0 commit ef5adac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hr_holidays_public/models/resource_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2018 Brainbean Apps
# Copyright 2020 InitOS Gmbh
# Copyright 2021 Tecnativa - Víctor Martínez
# Copyright 2024 Pierre Verkest
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
Expand Down Expand Up @@ -39,6 +40,10 @@ def _attendance_intervals_batch(
res = super()._attendance_intervals_batch(
start_dt=start_dt, end_dt=end_dt, resources=resources, domain=domain, tz=tz
)

if resources is None:
resources = [self.env["resource.resource"]]

if self.env.context.get("exclude_public_holidays") and resources:
return self._attendance_intervals_batch_exclude_public_holidays(
start_dt, end_dt, res, resources, tz
Expand Down
26 changes: 26 additions & 0 deletions hr_holidays_public/tests/test_holidays_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza
# Copyright 2018 Brainbean Apps
# Copyright 2020 InitOS Gmbh
# Copyright 2024 Pierre Verkest
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import datetime

from odoo.tests import common

Expand Down Expand Up @@ -191,3 +193,27 @@ def test_number_of_hours_excluding_employee_2(self):

self.assertEqual(leave_request.number_of_days, 2)
self.assertEqual(leave_request.number_of_hours_display, 16)

def test_compute_week_hours_without_public_holidays(self):
self.assertEqual(
self.calendar.with_context(
employee_id=self.employee_1.id, exclude_public_holidays=True
).get_work_hours_count(
datetime.combine(datetime(1946, 12, 16), datetime.min.time()),
datetime.combine(datetime(1946, 12, 22), datetime.max.time()),
compute_leaves=False,
),
40,
)

def test_compute_week_hours_with_public_holidays(self):
self.assertEqual(
self.calendar.with_context(
employee_id=self.employee_1.id, exclude_public_holidays=True
).get_work_hours_count(
datetime.combine(datetime(1946, 12, 23), datetime.min.time()),
datetime.combine(datetime(1946, 12, 29), datetime.max.time()),
compute_leaves=False,
),
32,
)

0 comments on commit ef5adac

Please sign in to comment.