[FIX] hr_holidays, resource: use employee time-zone for leave compute

Steps to reproduce:
- Create Allocation for 20 days for Mitchell Admin and validate (12/01 to 12/31).
- Set Working Schedule "Standard 40 hours/week" to UTC timezone.
- Set Mitchell Admin's timezone to Europe/Zurich.
- Create a time off with type Extra Time Off with dates 12/29 - 12/29 and try to save.
- Receive Validation Error: There is no valid allocation to cover that request.

Issues:
You cannot request that leave due to a timezone mismatch, even though you should be able to.

Solution:
To solve the zone mismatch we use the employee timezone to compute the
attendance intervals.

opw-3619178

closes odoo/odoo#146938

Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
This commit is contained in:
Mattis Megevand (mmeg)
2023-12-22 16:14:47 +00:00
parent d092f4cfee
commit 50652f265c
3 changed files with 7 additions and 5 deletions
+3 -2
View File
@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base64
from pytz import UTC
from pytz import timezone, UTC
from datetime import datetime, time
from random import choice
from string import digits
@@ -516,7 +516,8 @@ class HrEmployeePrivate(models.Model):
def _get_calendar_attendances(self, date_from, date_to):
self.ensure_one()
return self.resource_calendar_id.get_work_duration_data(date_from, date_to)
employee_timezone = timezone(self.tz) if self.tz else None
return self.resource_calendar_id.with_context(employee_timezone=employee_timezone).get_work_duration_data(date_from, date_to)
# ---------------------------------------------------------
# Business Methods
+3 -2
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from pytz import UTC
from pytz import timezone, UTC
from datetime import date, datetime, time
from odoo import api, fields, models
@@ -145,7 +145,8 @@ class Employee(models.Model):
valid_contracts = self.sudo()._get_contracts(date_from, date_to, states=['open', 'close'])
if not valid_contracts:
return super()._get_calendar_attendances(date_from, date_to)
return valid_contracts.resource_calendar_id.get_work_duration_data(date_from, date_to)
employee_timezone = timezone(self.tz) if self.tz else None
return valid_contracts.resource_calendar_id.with_context(employee_timezone=employee_timezone).get_work_duration_data(date_from, date_to)
def write(self, vals):
res = super().write(vals)
+1 -1
View File
@@ -428,7 +428,7 @@ class ResourceCalendar(models.Model):
else:
resources_list = list(resources) + [self.env['resource.resource']]
attendance_intervals = self._attendance_intervals_batch(start_dt, end_dt, resources, tz=tz)
attendance_intervals = self._attendance_intervals_batch(start_dt, end_dt, resources, tz=tz or self.env.context.get("employee_timezone"))
if compute_leaves:
leave_intervals = self._leave_intervals_batch(start_dt, end_dt, resources, domain, tz=tz)
return {