Skip to content

Commit

Permalink
[FIX] hr_holidays_public: show employee's public holidays in dashboard
Browse files Browse the repository at this point in the history
This change hooks into the core public holidays method that returns the
employee's available holidays for a period of time and displays them in
the Time Off dashboard calendar.

Both types of public holidays are compatible and will show up in order.

TT52276
  • Loading branch information
chienandalu committed Dec 19, 2024
1 parent ee03b7e commit 4bcdebf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions hr_holidays_public/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import hr_employee
from . import hr_leave
from . import hr_leave_type
from . import hr_holidays_public
Expand Down
43 changes: 43 additions & 0 deletions hr_holidays_public/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import datetime

from odoo import api, models


class HrEmployee(models.Model):
_inherit = "hr.employee"

def _get_public_holiday_lines(self, date_start, date_end):
"""Just get the employees holidays"""
domain = self.env["hr.leave"]._get_domain_from_get_unusual_days(

Check warning on line 13 in hr_holidays_public/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_holidays_public/models/hr_employee.py#L13

Added line #L13 was not covered by tests
date_from=date_start, date_to=date_end
)
return self.env["hr.holidays.public.line"].search(domain)

Check warning on line 16 in hr_holidays_public/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_holidays_public/models/hr_employee.py#L16

Added line #L16 was not covered by tests

@api.model
def get_public_holidays_data(self, date_start, date_end):
# Include public holidays in the calendar summary
res = super().get_public_holidays_data(date_start, date_end)
self = self._get_contextual_employee()
public_holidays = self._get_public_holiday_lines(date_start, date_end).sorted(

Check warning on line 23 in hr_holidays_public/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_holidays_public/models/hr_employee.py#L21-L23

Added lines #L21 - L23 were not covered by tests
"date"
)
res += list(

Check warning on line 26 in hr_holidays_public/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_holidays_public/models/hr_employee.py#L26

Added line #L26 was not covered by tests
map(
lambda bh: {
"id": -bh.id,
"colorIndex": 0,
"end": (datetime.combine(bh.date, datetime.max.time())).isoformat(),
"endType": "datetime",
"isAllDay": True,
"start": (
datetime.combine(bh.date, datetime.min.time())
).isoformat(),
"startType": "datetime",
"title": bh.name,
},
public_holidays,
)
)
return sorted(res, key=lambda x: x["start"])

Check warning on line 43 in hr_holidays_public/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_holidays_public/models/hr_employee.py#L43

Added line #L43 was not covered by tests

0 comments on commit 4bcdebf

Please sign in to comment.