From 4e6e3e62611940b94596097ad5ea4bbcb86d2cda Mon Sep 17 00:00:00 2001 From: mafo-odoo Date: Thu, 25 Aug 2022 11:04:51 +0000 Subject: [PATCH] [FIX] hr_holidays: no date_from creates error Probem: With some time off type as default type in an allocation request you get a traceback as soon as you try to open the allocation request form. Cause: FIX commit [1] introduced the issue as it didn't consider the possibility of a false date_from Improvement 1: Having a date_from False sets a False in the leave request name displayed on the form, we change that to have an empty string instead Improvement 2: The timezone bug fix in commit [1] is only applied on a specific configuration, we applie it to all configuration of leave request name [1] 5a50dea2652cff014d9198f59265cf36a3ec1865 opw-2961344 closes odoo/odoo#99454 X-original-commit: 3b9a012e4a0839bc5da2daf51d56591d2863b4be Signed-off-by: Kevin Baptiste Signed-off-by: Fockedey Martin (mafo) --- addons/hr_holidays/models/hr_leave.py | 15 ++++++++------- .../tests/test_performance.py | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index cf013d0661b..8dd0ff29f5b 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -775,6 +775,9 @@ class HolidaysRequest(models.Model): def name_get(self): res = [] for leave in self: + user_tz = timezone(leave.tz) + date_from_utc = leave.date_from and leave.date_from.astimezone(user_tz).date() + date_to_utc = leave.date_to and leave.date_to.astimezone(user_tz).date() if self.env.context.get('short_name'): if leave.leave_type_request_unit == 'hour': res.append((leave.id, _("%s : %.2f hours") % (leave.name or leave.holiday_status_id.name, leave.number_of_hours_display))) @@ -799,25 +802,23 @@ class HolidaysRequest(models.Model): person=target, leave_type=leave.holiday_status_id.name, duration=leave.number_of_hours_display, - date=fields.Date.to_string(leave.date_from), + date=fields.Date.to_string(date_from_utc) or "", ) )) else: - user_tz = timezone(leave.tz) - date_from_utc = leave.date_from and leave.date_from.astimezone(user_tz).date() res.append(( leave.id, _("%(person)s on %(leave_type)s: %(duration).2f hours on %(date)s", person=target, leave_type=leave.holiday_status_id.name, duration=leave.number_of_hours_display, - date=fields.Date.to_string(date_from_utc), + date=fields.Date.to_string(date_from_utc) or "", ) )) else: - display_date = fields.Date.to_string(leave.date_from) - if leave.number_of_days > 1: - display_date += ' / %s' % fields.Date.to_string(leave.date_to) + display_date = fields.Date.to_string(date_from_utc) or "" + if leave.number_of_days > 1 and date_from_utc and date_to_utc: + display_date += ' / %s' % fields.Date.to_string(date_to_utc) or "" if self.env.context.get('hide_employee_name') and 'employee_id' in self.env.context.get('group_by', []): res.append(( leave.id, diff --git a/addons/hr_work_entry_holidays/tests/test_performance.py b/addons/hr_work_entry_holidays/tests/test_performance.py index 6b73aff424f..815e1548539 100644 --- a/addons/hr_work_entry_holidays/tests/test_performance.py +++ b/addons/hr_work_entry_holidays/tests/test_performance.py @@ -47,7 +47,7 @@ class TestWorkEntryHolidaysPerformance(TestWorkEntryHolidaysBase): @users('__system__', 'admin') @warmup def test_performance_leave_create(self): - with self.assertQueryCount(__system__=27, admin=28): # 25/26 com + with self.assertQueryCount(__system__=28, admin=29): # 25/26 com leave = self.create_leave(datetime(2018, 1, 1, 7, 0), datetime(2018, 1, 1, 18, 0)) leave.action_refuse() @@ -56,7 +56,7 @@ class TestWorkEntryHolidaysPerformance(TestWorkEntryHolidaysBase): def test_performance_leave_confirm(self): leave = self.create_leave(datetime(2018, 1, 1, 7, 0), datetime(2018, 1, 1, 18, 0)) leave.action_draft() - with self.assertQueryCount(__system__=23, admin=24): + with self.assertQueryCount(__system__=24, admin=25): leave.action_confirm() leave.state = 'refuse'