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.

38 lines
1.3 KiB

  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  2. from odoo import models, tools
  3. class BiSQLView(models.Model):
  4. _inherit = 'bi.sql.view'
  5. def check_manual_fields(self, model):
  6. # check the fields we need are defined on self, to stop it going
  7. # early on install / startup - particularly problematic during upgrade
  8. if 'group_operator' in tools.table_columns(
  9. self.env.cr, 'bi_sql_view_field') and\
  10. model._name.startswith(self._model_prefix):
  11. # Use SQL instead of ORM, as ORM might not be fully initialised -
  12. # we have no control over the order that fields are defined!
  13. # We are not concerned about user security rules.
  14. self.env.cr.execute(
  15. """
  16. SELECT
  17. f.name,
  18. f.ttype,
  19. f.group_operator
  20. FROM
  21. bi_sql_view v
  22. LEFT JOIN bi_sql_view_field f ON f.bi_sql_view_id = v.id
  23. WHERE
  24. v.model_name = %s
  25. ;
  26. """, (model._name,)
  27. )
  28. sql_fields = self.env.cr.fetchall()
  29. for sql_field in sql_fields:
  30. if sql_field[0] in model._fields and\
  31. sql_field[1] in ('integer', 'float') and\
  32. sql_field[2]:
  33. model._fields[sql_field[0]].group_operator = sql_field[2]