From 5ccc3f66e88fa5492d699484b2dd70a3142d10b7 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 5 Sep 2018 11:51:05 +0200 Subject: [PATCH] [FIX] web: read_progress_bar: convert dates to strings Since rev. 960360af, Date (resp. Datetime) fields return datetime.date (resp. datetime.datetime) objects. This caused an issue in the read_progress_bar method which returns a dict, whose keys are values of the group_by. Indeed, when grouped on a Date or Datetime field, the key was no longer a string but a datetime.date or datetime.datetime object, and it crashed when that dict was turned into a JSON string. This method isn't tested at all for now, but tests will come shortly. Task 1878254. --- addons/web/models/models.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/web/models/models.py b/addons/web/models/models.py index 09e5478caf6..572f07333d2 100644 --- a/addons/web/models/models.py +++ b/addons/web/models/models.py @@ -37,8 +37,7 @@ class Base(models.AbstractModel): 'quarter': 'QQQ yyyy', 'year': 'yyyy'} - fields = [progress_bar['field'], group_by] - records_values = self.search_read(domain or [], fields) + records_values = self.search_read(domain or [], [progress_bar['field'], group_by]) data = {} for record_values in records_values: @@ -46,10 +45,9 @@ class Base(models.AbstractModel): # Again, imitating what _read_group_format_result and _read_group_prepare_data do field_type = self._fields[group_by].type - if field_type in ['date', 'datetime'] and isinstance(group_by_value, pycompat.string_types): + if group_by_value and field_type in ['date', 'datetime']: locale = self._context.get('lang') or 'en_US' - dt_format = DEFAULT_SERVER_DATETIME_FORMAT if field_type == 'datetime' else DEFAULT_SERVER_DATE_FORMAT - group_by_value = datetime.strptime(group_by_value, dt_format) + group_by_value = fields.Datetime.to_datetime(group_by_value) group_by_value = pytz.timezone('UTC').localize(group_by_value) tz_info = None if field_type == 'datetime' and self._context.get('tz') in pytz.all_timezones: