|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
|
from odoo import api, fields, models |
|
|
from odoo import api, fields, models |
|
|
import ast |
|
|
import ast |
|
|
|
|
|
from odoo.tools.safe_eval import safe_eval |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KpiKpi(models.Model): |
|
|
class KpiKpi(models.Model): |
|
@ -13,7 +14,7 @@ class KpiKpi(models.Model): |
|
|
active = fields.Boolean(default=True) |
|
|
active = fields.Boolean(default=True) |
|
|
cron_id = fields.Many2one("ir.cron", readonly=True, copy=False) |
|
|
cron_id = fields.Many2one("ir.cron", readonly=True, copy=False) |
|
|
computation_method = fields.Selection( |
|
|
computation_method = fields.Selection( |
|
|
[("function", "Function")], required=True |
|
|
|
|
|
|
|
|
[("function", "Function"), ("code", "Code")], required=True |
|
|
) |
|
|
) |
|
|
value = fields.Serialized() |
|
|
value = fields.Serialized() |
|
|
dashboard_item_ids = fields.One2many("kpi.dashboard.item", inverse_name="kpi_id") |
|
|
dashboard_item_ids = fields.One2many("kpi.dashboard.item", inverse_name="kpi_id") |
|
@ -34,6 +35,7 @@ class KpiKpi(models.Model): |
|
|
inverse_name='kpi_id', |
|
|
inverse_name='kpi_id', |
|
|
help="Actions that can be opened from the KPI" |
|
|
help="Actions that can be opened from the KPI" |
|
|
) |
|
|
) |
|
|
|
|
|
code = fields.Text("Code") |
|
|
|
|
|
|
|
|
def _cron_vals(self): |
|
|
def _cron_vals(self): |
|
|
return { |
|
|
return { |
|
@ -84,6 +86,17 @@ class KpiKpi(models.Model): |
|
|
vals["value_last_update"] = fields.Datetime.now() |
|
|
vals["value_last_update"] = fields.Datetime.now() |
|
|
return super().write(vals) |
|
|
return super().write(vals) |
|
|
|
|
|
|
|
|
|
|
|
def _get_code_input_dict(self): |
|
|
|
|
|
return { |
|
|
|
|
|
"self": self, |
|
|
|
|
|
"model": self, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def _compute_value_code(self): |
|
|
|
|
|
results = self._get_code_input_dict() |
|
|
|
|
|
safe_eval(self.code or "", results, mode="exec", nocopy=True) |
|
|
|
|
|
return results.get("result", {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KpiKpiAction(models.Model): |
|
|
class KpiKpiAction(models.Model): |
|
|
_name = 'kpi.kpi.action' |
|
|
_name = 'kpi.kpi.action' |
|
|