Skip to content

Commit 15cfe4f

Browse files
committed
Merge PR OCA#225 into 17.0
Signed-off-by pedrobaeza
2 parents d514ab8 + 5421e4f commit 15cfe4f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

hr_holidays_public/models/resource_calendar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2018 Brainbean Apps
33
# Copyright 2020 InitOS Gmbh
44
# Copyright 2021 Tecnativa - Víctor Martínez
5+
# Copyright 2024 Pierre Verkest
56
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
67

78
from odoo import models
@@ -44,6 +45,8 @@ def _attendance_intervals_batch(
4445
tz=tz,
4546
lunch=lunch,
4647
)
48+
if resources is None:
49+
resources = [self.env["resource.resource"]]
4750
if self.env.context.get("exclude_public_holidays") and resources:
4851
return self._attendance_intervals_batch_exclude_public_holidays(
4952
start_dt, end_dt, res, resources, tz

hr_holidays_public/tests/test_holidays_calculation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza
33
# Copyright 2018 Brainbean Apps
44
# Copyright 2020 InitOS Gmbh
5+
# Copyright 2024 Pierre Verkest
56
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
7+
from datetime import datetime
68

79
from odoo.tests.common import TransactionCase
810

@@ -188,3 +190,27 @@ def test_number_of_hours_excluding_employee_2(self):
188190

189191
self.assertEqual(leave_request.number_of_days, 2)
190192
self.assertEqual(leave_request.number_of_hours_display, 16)
193+
194+
def test_compute_week_hours_without_public_holidays(self):
195+
self.assertEqual(
196+
self.calendar.with_context(
197+
employee_id=self.employee_1.id, exclude_public_holidays=True
198+
).get_work_hours_count(
199+
datetime.combine(datetime(1946, 12, 16), datetime.min.time()),
200+
datetime.combine(datetime(1946, 12, 22), datetime.max.time()),
201+
compute_leaves=False,
202+
),
203+
40,
204+
)
205+
206+
def test_compute_week_hours_with_public_holidays(self):
207+
self.assertEqual(
208+
self.calendar.with_context(
209+
employee_id=self.employee_1.id, exclude_public_holidays=True
210+
).get_work_hours_count(
211+
datetime.combine(datetime(1946, 12, 23), datetime.min.time()),
212+
datetime.combine(datetime(1946, 12, 29), datetime.max.time()),
213+
compute_leaves=False,
214+
),
215+
32,
216+
)

0 commit comments

Comments
 (0)