Skip to content

Commit 2c940bb

Browse files
robinengelsLaurent Stukkens (LTU)
authored andcommitted
[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#87345 X-original-commit: 5e3ee49 Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com> Signed-off-by: Engels Robin (roen) <roen@odoo.com>
1 parent 1ff9ad0 commit 2c940bb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

addons/hr_timesheet/controllers/portal.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections import OrderedDict
55
from dateutil.relativedelta import relativedelta
66
from operator import itemgetter
7-
from datetime import datetime
87

98
from odoo import fields, http, _
109
from odoo.http import request
@@ -137,11 +136,13 @@ def get_timesheets():
137136
timesheets = Timesheet_sudo.search(domain, order=orderby, limit=_items_per_page, offset=pager['offset'])
138137
if field:
139138
if groupby == 'date':
140-
time_data = Timesheet_sudo.read_group(domain, ['date', 'unit_amount:sum'], ['date:day'])
141-
mapped_time = dict([(datetime.strptime(m['date:day'], '%d %b %Y').date(), m['unit_amount']) for m in time_data])
142-
grouped_timesheets = [(Timesheet_sudo.concat(*g), mapped_time[k]) for k, g in groupbyelem(timesheets, itemgetter('date'))]
139+
raw_timesheets_group = Timesheet_sudo.read_group(
140+
domain, ["unit_amount:sum", "ids:array_agg(id)"], ["date:day"]
141+
)
142+
grouped_timesheets = [(Timesheet_sudo.browse(group["ids"]), group["unit_amount"]) for group in raw_timesheets_group]
143+
143144
else:
144-
time_data = time_data = Timesheet_sudo.read_group(domain, [field, 'unit_amount:sum'], [field])
145+
time_data = Timesheet_sudo.read_group(domain, [field, 'unit_amount:sum'], [field])
145146
mapped_time = dict([(m[field][0] if m[field] else False, m['unit_amount']) for m in time_data])
146147
grouped_timesheets = [(Timesheet_sudo.concat(*g), mapped_time[k.id]) for k, g in groupbyelem(timesheets, itemgetter(field))]
147148
return timesheets, grouped_timesheets

0 commit comments

Comments
 (0)