From 1dd6fa6b64b3795acbdbd734935cf66e8df13ea7 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Thu, 17 Mar 2022 10:04:52 +0000 Subject: [PATCH] [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) Signed-off-by: Engels Robin (roen) --- addons/hr_timesheet/controllers/portal.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/hr_timesheet/controllers/portal.py b/addons/hr_timesheet/controllers/portal.py index 085f0429865..ec07c343ef2 100644 --- a/addons/hr_timesheet/controllers/portal.py +++ b/addons/hr_timesheet/controllers/portal.py @@ -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