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

[17.0][FIX] hr_holidays_public: show employee's public holidays in dashboard #157

Merged
Merged
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
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
Loading