From c73aca2e7ada4dd2a88d886f668051f277d21b7d Mon Sep 17 00:00:00 2001 From: Leonardo Pavan Rocha Date: Mon, 30 Oct 2023 15:35:38 +0000 Subject: [PATCH] [FIX] hr_holidays: fix multi day leaves not being rendered After https://github.com/odoo/odoo/pull/109736, we started rendering all day events in the all day slot. However, some calendar views don't have an all day slot, so these events weren't being shown. Therefore, this commit adds an all day slot to the hr_holidays module to show multiple day events. Therefore, we add a new last_several_days computed field in hr leave. task-3566710 closes odoo/odoo#150980 X-original-commit: cdd8b2fb6b5b3c6a7b1d163368eef791d3d14b3a Signed-off-by: Yannick Tivisse (yti) --- addons/hr_holidays/models/hr_leave.py | 6 ++++++ .../src/views/calendar/calendar_model.js | 19 ++++++++++--------- addons/hr_holidays/views/hr_leave_views.xml | 9 ++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 40e0c7de4f2..3cf290f881a 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -176,6 +176,7 @@ class HolidaysRequest(models.Model): number_of_hours = fields.Float( 'Duration (Hours)', compute='_compute_duration', store=True, tracking=True, help='Number of hours of the time off request. Used in the calculation.') + last_several_days = fields.Boolean("All day", compute="_compute_last_several_days") number_of_days_display = fields.Float( 'Duration in days', compute='_compute_number_of_days_display', help='Number of days of the time off request according to your working schedule. Used for interface.') @@ -582,6 +583,11 @@ class HolidaysRequest(models.Model): or holiday.department_id.company_id \ or self.env.company + @api.depends('number_of_days') + def _compute_last_several_days(self): + for holiday in self: + holiday.last_several_days = holiday.number_of_days > 1 + @api.depends('tz') @api.depends_context('uid') def _compute_tz_mismatch(self): diff --git a/addons/hr_holidays/static/src/views/calendar/calendar_model.js b/addons/hr_holidays/static/src/views/calendar/calendar_model.js index ad218d1b7c9..7c899d62be3 100644 --- a/addons/hr_holidays/static/src/views/calendar/calendar_model.js +++ b/addons/hr_holidays/static/src/views/calendar/calendar_model.js @@ -26,19 +26,20 @@ export class TimeOffCalendarModel extends CalendarModel { } makeContextDefaults(record) { - const { scale } = this.meta; const context = super.makeContextDefaults(record); if (this.employeeId) { - context['default_employee_id'] = this.employeeId; + context["default_employee_id"] = this.employeeId; } - if(['day', 'week'].includes(scale)) { - if ('default_date_from' in context) { - context['default_date_from'] = serializeDateTime(deserializeDateTime(context['default_date_from']).set({ hours: 7 })); - } - if ('default_date_to' in context) { - context['default_date_to'] = serializeDateTime(deserializeDateTime(context['default_date_from']).set({ hours: 19 })); - } + if ("default_date_from" in context) { + context["default_date_from"] = serializeDateTime( + deserializeDateTime(context["default_date_from"]).set({ hours: 7 }) + ); + } + if ("default_date_to" in context) { + context["default_date_to"] = serializeDateTime( + deserializeDateTime(context["default_date_from"]).set({ hours: 19 }) + ); } return context; } diff --git a/addons/hr_holidays/views/hr_leave_views.xml b/addons/hr_holidays/views/hr_leave_views.xml index 211ab46dac0..dc5bde16223 100644 --- a/addons/hr_holidays/views/hr_leave_views.xml +++ b/addons/hr_holidays/views/hr_leave_views.xml @@ -413,7 +413,8 @@ show_unusual_days="True" color="color" hide_time="True" - mode="year"> + mode="year" + all_day="last_several_days"> @@ -438,7 +439,8 @@ quick_create="0" show_unusual_days="True" color="color" - hide_time="True"> + hide_time="True" + all_day="last_several_days"> @@ -494,7 +496,8 @@ mode="month" show_unusual_days="True" quick_create="0" - color="color"> + color="color" + all_day="last_several_days">