Last active
April 30, 2025 17:35
-
-
Save ofelix03/dbe6d348d12bc8e1244c9321f01489f3 to your computer and use it in GitHub Desktop.
Medium Article - HR Leave - Model Override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from odoo import models, api | |
class HrLeave(models.Model): | |
_inherit = "hr.leave" | |
@api.model | |
def get_employee_timeoff_periods(self, res_model, res_ids): | |
if res_model == "planning.slot": | |
# the res_ids supplied is rather the resource ids | |
# and not the employee ids, let therefore infer the | |
# employee ids from the reosurce records | |
employees = self.env["hr.employee"].search([("resource_id", "in", res_ids)]) | |
employee_ids = employees.ids | |
else: | |
employee_ids = res_ids | |
timeoffs = self.search([("employee_id", "in", employee_ids)]) | |
timeoff_periods_per_employee = defaultdict(list) | |
for t in timeoffs: | |
if res_model == "planning.slot": | |
res_id = t.employee_id.resource_id.id | |
else: | |
res_id = t.employee_id.id | |
timeoff_periods_per_employee[res_id].append( | |
[ | |
t.request_date_from, | |
t.request_date_to, | |
t.holiday_status_id.name, | |
t.holiday_status_id.icon_id.name, | |
] | |
) | |
return timeoff_periods_per_employee |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment