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.

50 lines
1.4 KiB

  1. # Copyright 2020 Creu Blanca
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import fields, models
  4. import logging
  5. _logger = logging.getLogger(__name__)
  6. try:
  7. from bokeh.plotting import figure
  8. from bokeh.themes import Theme
  9. from bokeh.embed import components
  10. except ImportError as e:
  11. _logger.error(e)
  12. class KpiKpi(models.Model):
  13. _inherit = "kpi.kpi"
  14. widget = fields.Selection(selection_add=[("bokeh", "Bokeh")])
  15. def _get_bokeh_theme(self):
  16. return Theme(json={
  17. "attrs": {
  18. "Figure": {
  19. "background_fill_alpha": 0,
  20. "border_fill_alpha": 0,
  21. "outline_line_alpha": 0,
  22. },
  23. "Legend": {
  24. "border_line_alpha": 0,
  25. "background_fill_alpha": 0,
  26. },
  27. "ColorBar": {
  28. "bar_line_alpha": 0,
  29. "background_fill_alpha": 0,
  30. },
  31. }
  32. })
  33. def _get_code_input_dict(self):
  34. res = super()._get_code_input_dict()
  35. if self.widget == 'bokeh':
  36. res.update({
  37. 'figure': figure,
  38. 'components': components,
  39. 'simple_components': lambda r: components(
  40. r, theme=self._get_bokeh_theme())
  41. })
  42. return res