summaryrefslogtreecommitdiff
path: root/addons/web/models
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2017-11-27 17:10:45 +0100
committerLucas Perais (lpe) <lpe@odoo.com>2017-12-18 09:16:11 +0100
commit9de2bd54e5dea1d62f4ffbb63dd9f809d339902b (patch)
tree295e1287a3a2adfc16049fd2bcbad1806abca390 /addons/web/models
parent38bde51563ec6e42c166422597be9ef2f55e5685 (diff)
[FIX] web: fix progress_bar if grouped by date:interval
Before this commit, when grouping a kanban by date with a modifier e.g. crm.lead grouped by create_date:month A traceback was thrown on the python side bacause create_date:month was literally not a field After this commit, the progress bar in that situation displays well, at the price of copying bits of the read_group infrastructure OPW 785021
Diffstat (limited to 'addons/web/models')
-rw-r--r--addons/web/models/models.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/addons/web/models/models.py b/addons/web/models/models.py
index 09d56349048..edf167df6c9 100644
--- a/addons/web/models/models.py
+++ b/addons/web/models/models.py
@@ -1,7 +1,13 @@
# -*- coding: utf-8 -*-
+from datetime import datetime
+import babel.dates
+import pytz
+from odoo.tools import pycompat
+from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
from odoo import _, api, fields, models
+
class Base(models.AbstractModel):
_inherit = 'base'
@@ -19,12 +25,43 @@ class Base(models.AbstractModel):
:return a dictionnary mapping group_by values to dictionnaries mapping
progress bar field values to the related number of records
"""
+
+ # Workaround to match read_group's infrastructure
+ # TO DO in master: harmonize this function and readgroup to allow factorization
+ group_by_modifier = group_by.partition(':')[2] or 'month'
+ group_by = group_by.partition(':')[0]
+ display_date_formats = {
+ 'day': 'dd MMM yyyy',
+ 'week': "'W'w YYYY",
+ 'month': 'MMMM yyyy',
+ 'quarter': 'QQQ yyyy',
+ 'year': 'yyyy'}
+
fields = [progress_bar['field'], group_by]
records_values = self.search_read(domain or [], fields)
data = {}
for record_values in records_values:
group_by_value = record_values[group_by]
+
+ # 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):
+ 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 = pytz.timezone('UTC').localize(group_by_value)
+ tz_info = None
+ if field_type == 'datetime' and self._context.get('tz') in pytz.all_timezones:
+ tz_info = self._context.get('tz')
+ group_by_value = babel.dates.format_datetime(
+ group_by_value, format=display_date_formats[group_by_modifier],
+ tzinfo=tz_info, locale=locale)
+ else:
+ group_by_value = babel.dates.format_date(
+ group_by_value, format=display_date_formats[group_by_modifier],
+ locale=locale)
+
if type(group_by_value) == tuple:
group_by_value = group_by_value[1] # FIXME should use technical value (0)