[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 <kba@odoo.com>
Signed-off-by: Fockedey Martin (mafo) <mafo@odoo.com>
This commit is contained in:
mafo-odoo
2022-09-02 15:27:59 +02:00
parent 83d6ba6e0d
commit 4e6e3e6261
2 changed files with 10 additions and 9 deletions
+8 -7
View File
@@ -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,
@@ -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'