OCA reporting engine fork for dev and update.
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
1.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. # Copyright 2017-2019 Onestein (<https://www.onestein.eu>)
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. import logging
  4. from odoo import _, api, models
  5. from odoo.exceptions import UserError
  6. _logger = logging.getLogger(__name__)
  7. @api.model
  8. def _bi_view(_name):
  9. return _name.startswith("x_bve.")
  10. _auto_init_orig = models.BaseModel._auto_init
  11. @api.model_cr_context
  12. def _auto_init(self):
  13. # This monkey patch is meant to fix an error (probably
  14. # introduced by https://github.com/odoo/odoo/pull/15412), while
  15. # running an update all. The _auto_init() method invoked during
  16. # an update all is the one of BaseModel, and not the one of Base.
  17. # This monkey patch seems not working if defined inside the post_load()
  18. if _bi_view(self._name):
  19. return
  20. return _auto_init_orig(self)
  21. models.BaseModel._auto_init = _auto_init
  22. class Base(models.AbstractModel):
  23. _inherit = "base"
  24. @api.model
  25. def _setup_complete(self):
  26. if not _bi_view(self._name):
  27. super()._setup_complete()
  28. else:
  29. self.pool.models[self._name]._log_access = False
  30. @api.model
  31. def _read_group_process_groupby(self, gb, query):
  32. if not _bi_view(self._name):
  33. return super()._read_group_process_groupby(gb, query)
  34. split = gb.split(":")
  35. if split[0] not in self._fields:
  36. raise UserError(_("No data to be displayed."))
  37. return super()._read_group_process_groupby(gb, query)
  38. @api.model
  39. def _add_magic_fields(self):
  40. if _bi_view(self._name):
  41. self._log_access = False
  42. return super()._add_magic_fields()