You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.5 KiB

# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2018 MuK IT GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###################################################################################
import re
import pytz
import hashlib
import logging
import psycopg2
from odoo import _
from odoo import models, api, fields
from odoo.tools import ustr, pycompat, human_size
_logger = logging.getLogger(__name__)
_read_group_process_groupby = models.BaseModel._read_group_process_groupby
def _read_group_process_groupby_hour(self, gb, query):
split = gb.split(':')
field_type = self._fields[split[0]].type
gb_function = split[1] if len(split) == 2 else None
temporal = field_type in ('date', 'datetime')
tz_convert = field_type == 'datetime' and self._context.get('tz') in pytz.all_timezones
qualified_field = self._inherits_join_calc(self._table, split[0], query)
if temporal and gb_function in ['hour']:
if tz_convert:
qualified_field = "timezone('%s', timezone('UTC',%s))" % (self._context.get('tz', 'UTC'), qualified_field)
qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
if field_type == 'boolean':
qualified_field = "coalesce(%s,false)" % qualified_field
return {
'field': split[0],
'groupby': gb,
'type': field_type,
'display_format': 'hh:00 dd MMM',
'interval': dateutil.relativedelta.relativedelta(hours=1),
'tz_convert': tz_convert,
'qualified_field': qualified_field
}
return _read_group_process_groupby(self, gb, query)
models.BaseModel._read_group_process_groupby = _read_group_process_groupby_hour