Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] hr_holidays_public: calendar.get_work_hours_count #142

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
Loading