[FIX] hr_timesheet: Fix traceback when grouping timesheets by date

Current behavior:
When accessing your timesheets with /my/timesheets/ and changing language to something else than english
you get a traceback

Steps to reproduce:
- Have timesheets app installed
- Have atleast one other language than english installed (e.g French)
- Go to /my/timesheets and group the timesheets by date
- Change the language by accessing for example fr_FR/my/timesheets
- You get a traceback, because we try to convert a string into a datetime object wich is not working correctly with different languages

opw-2785268

closes odoo/odoo#87381

X-original-commit: 5e3ee492c97dddb6f9430144429febfa6327d4d0
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2022-03-29 01:20:30 +02:00
committed by Laurent Stukkens (LTU)
parent ed9814059b
commit 1dd6fa6b64
+6 -5
View File
@@ -4,7 +4,6 @@
from collections import OrderedDict
from dateutil.relativedelta import relativedelta
from operator import itemgetter
from datetime import datetime
from odoo import fields, http, _
from odoo.http import request
@@ -138,11 +137,13 @@ class TimesheetCustomerPortal(CustomerPortal):
timesheets = Timesheet_sudo.search(domain, order=orderby, limit=_items_per_page, offset=pager['offset'])
if field:
if groupby == 'date':
time_data = Timesheet_sudo.read_group(domain, ['date', 'unit_amount:sum'], ['date:day'])
mapped_time = dict([(datetime.strptime(m['date:day'], '%d %b %Y').date(), m['unit_amount']) for m in time_data])
grouped_timesheets = [(Timesheet_sudo.concat(*g), mapped_time[k]) for k, g in groupbyelem(timesheets, itemgetter('date'))]
raw_timesheets_group = Timesheet_sudo.read_group(
domain, ["unit_amount:sum", "ids:array_agg(id)"], ["date:day"]
)
grouped_timesheets = [(Timesheet_sudo.browse(group["ids"]), group["unit_amount"]) for group in raw_timesheets_group]
else:
time_data = time_data = Timesheet_sudo.read_group(domain, [field, 'unit_amount:sum'], [field])
time_data = Timesheet_sudo.read_group(domain, [field, 'unit_amount:sum'], [field])
mapped_time = dict([(m[field][0] if m[field] else False, m['unit_amount']) for m in time_data])
grouped_timesheets = [(Timesheet_sudo.concat(*g), mapped_time[k.id]) for k, g in groupbyelem(timesheets, itemgetter(field))]
return timesheets, grouped_timesheets