[FIX] hr_holidays: handle tz attribute error if user timezone empty
When a user tries to create a leave request without linking an employee with the user and without a configured login user timezone, a traceback will be generated. Steps to reproduce: - Install the "hr_holidays" module. - Create a new user, e.g., "Test user", and login with another browser. - Login as an admin user and go to Settings > Users & Companies. - Search for "Test user" and set Timzone as empty. - Go to the Time Off menu and create a leave request; after that, a traceback will be generated. Error: AttributeError: 'bool' object has no attribute 'upper' When a user tries to create a leave request without linking an employee with the user and without a configured login user timezone, the _get_start_or_end_from_attendance() function of the "hr.leave" object will call at that time timzone not getting. Code reference: https://github.com/odoo/odoo/blob/15.0/addons/hr_holidays/models/hr_leave.py#L111 Sentry-4441512696 closes odoo/odoo#134434 X-original-commit: 904edbdbbc5e11608d7e3f3f7d2d3001b6247ed2 Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com> Signed-off-by: Pradip Yenpure (prye) <prye@odoo.com>
This commit is contained in:
@@ -308,7 +308,7 @@ class HrEmployee(models.Model):
|
||||
@api.model
|
||||
def get_public_holidays_data(self, date_start, date_end):
|
||||
self = self._get_contextual_employee()
|
||||
employee_tz = pytz.timezone(self._get_tz() if self else self.env.user.tz)
|
||||
employee_tz = pytz.timezone(self._get_tz() if self else self.env.user.tz or 'utc')
|
||||
public_holidays = self._get_public_holidays(date_start, date_end).sorted('date_from')
|
||||
return list(map(lambda bh: {
|
||||
'id': -bh.id,
|
||||
|
||||
@@ -1565,7 +1565,7 @@ class HolidaysRequest(models.Model):
|
||||
|
||||
def _to_utc(self, date, hour, resource):
|
||||
hour = float_to_time(float(hour))
|
||||
holiday_tz = timezone(resource.tz or self.env.user.tz)
|
||||
holiday_tz = timezone(resource.tz or self.env.user.tz or 'UTC')
|
||||
return holiday_tz.localize(datetime.combine(date, hour)).astimezone(UTC).replace(tzinfo=None)
|
||||
|
||||
def _get_attendances(self, request_date_from, request_date_to):
|
||||
|
||||
Reference in New Issue
Block a user