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.

58 lines
2.4 KiB

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