|
4 | 4 | from collections import OrderedDict
|
5 | 5 | from dateutil.relativedelta import relativedelta
|
6 | 6 | from operator import itemgetter
|
7 |
| -from datetime import datetime |
8 | 7 |
|
9 | 8 | from odoo import fields, http, _
|
10 | 9 | from odoo.http import request
|
@@ -137,11 +136,13 @@ def get_timesheets():
|
137 | 136 | timesheets = Timesheet_sudo.search(domain, order=orderby, limit=_items_per_page, offset=pager['offset'])
|
138 | 137 | if field:
|
139 | 138 | 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 | + |
143 | 144 | 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]) |
145 | 146 | mapped_time = dict([(m[field][0] if m[field] else False, m['unit_amount']) for m in time_data])
|
146 | 147 | grouped_timesheets = [(Timesheet_sudo.concat(*g), mapped_time[k.id]) for k, g in groupbyelem(timesheets, itemgetter(field))]
|
147 | 148 | return timesheets, grouped_timesheets
|
|
0 commit comments