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

7 years ago
7 years ago
7 years ago
  1. # -*- coding: utf-8 -*-
  2. ###################################################################################
  3. #
  4. # Copyright (C) 2018 MuK IT GmbH
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ###################################################################################
  20. import re
  21. import pytz
  22. import hashlib
  23. import logging
  24. import psycopg2
  25. import dateutil
  26. from odoo import _
  27. from odoo import models, api, fields
  28. from odoo.tools import ustr, pycompat, human_size
  29. _logger = logging.getLogger(__name__)
  30. _read_group_process_groupby = models.BaseModel._read_group_process_groupby
  31. def _read_group_process_groupby_hour(self, gb, query):
  32. split = gb.split(':')
  33. field_type = self._fields[split[0]].type
  34. gb_function = split[1] if len(split) == 2 else None
  35. temporal = field_type in ('date', 'datetime')
  36. tz_convert = field_type == 'datetime' and self._context.get('tz') in pytz.all_timezones
  37. qualified_field = self._inherits_join_calc(self._table, split[0], query)
  38. if temporal and gb_function in ['hour']:
  39. if tz_convert:
  40. qualified_field = "timezone('%s', timezone('UTC',%s))" % (self._context.get('tz', 'UTC'), qualified_field)
  41. qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
  42. if field_type == 'boolean':
  43. qualified_field = "coalesce(%s,false)" % qualified_field
  44. return {
  45. 'field': split[0],
  46. 'groupby': gb,
  47. 'type': field_type,
  48. 'display_format': 'hh:00 dd MMM',
  49. 'interval': dateutil.relativedelta.relativedelta(hours=1),
  50. 'tz_convert': tz_convert,
  51. 'qualified_field': qualified_field
  52. }
  53. return _read_group_process_groupby(self, gb, query)
  54. models.BaseModel._read_group_process_groupby = _read_group_process_groupby_hour