Skip to content

Commit

Permalink
[REF] kpi: module reformed and adapted to new versions
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasperalta1 committed Aug 19, 2024
1 parent 6e2b57c commit b5bfd94
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 510 deletions.
4 changes: 0 additions & 4 deletions kpi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
"security/ir.model.access.csv",
"views/kpi_category_views.xml",
"views/kpi_history_views.xml",
"views/kpi_threshold_range_views.xml",
"views/kpi_threshold_views.xml",
"views/kpi_views.xml",
"views/menu.xml",
"data/kpi_data.xml",
],
"images": [
"images/kpi_definition.png",
"images/kpi_computation.png",
"images/kpi_threshold.png",
"images/kpi_range.png",
],
"installable": True,
}
2 changes: 0 additions & 2 deletions kpi/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import kpi_category
from . import kpi_threshold_range
from . import kpi_threshold
from . import kpi_history
from . import kpi
15 changes: 1 addition & 14 deletions kpi/models/kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class KPI(models.Model):
name = fields.Char(required=True)
description = fields.Text()
category_id = fields.Many2one("kpi.category", required=True)
threshold_id = fields.Many2one("kpi.threshold", required=True)
periodicity = fields.Integer(default=1)

periodicity_uom = fields.Selection(
Expand Down Expand Up @@ -85,7 +84,6 @@ class KPI(models.Model):
"KPI Computation Type",
)

dbsource_id = fields.Many2one("base.external.dbsource", "External DB Source")
kpi_code = fields.Text(
help=(
"SQL code must return the result as 'value' " "(i.e. 'SELECT 5 AS value')."
Expand Down Expand Up @@ -121,29 +119,18 @@ def _get_kpi_value(self):
self.ensure_one()
kpi_value = 0
if self.kpi_code:
if self.kpi_type == "local" and is_sql_or_ddl_statement(self.kpi_code):
if self.kpi_type == "sql" and is_sql_or_ddl_statement(self.kpi_code):
self.env.cr.execute(self.kpi_code)
dic = self.env.cr.dictfetchall()
if is_one_value(dic):
kpi_value = dic[0]["value"]
elif (
self.kpi_type == "external"
and self.dbsource_id.id
and is_sql_or_ddl_statement(self.kpi_code)
):
dbsrc_obj = self.dbsource_id
res = dbsrc_obj.execute(self.kpi_code)
if is_one_value(res):
kpi_value = res[0]["value"]
elif self.kpi_type == "python":
kpi_value = safe_eval(self.kpi_code, {"self": self})
if isinstance(kpi_value, dict):
res = kpi_value
else:
threshold_obj = self.threshold_id
res = {
"value": kpi_value,
"color": threshold_obj.get_color(kpi_value),
}
res.update({"kpi_id": self.id})
return res
Expand Down
92 changes: 0 additions & 92 deletions kpi/models/kpi_threshold.py

This file was deleted.

174 changes: 0 additions & 174 deletions kpi/models/kpi_threshold_range.py

This file was deleted.

5 changes: 0 additions & 5 deletions kpi/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"access_kpi_user","kpi.user","model_kpi","base.group_user",1,0,0,0
"access_kpi_history_user","kpi.history.user","model_kpi_history","base.group_user",1,0,0,0
"access_kpi_category_user","kpi.category.user","model_kpi_category","base.group_user",1,0,0,0
"access_kpi_threshold_user","kpi.threshold.user","model_kpi_threshold","base.group_user",1,0,0,0
"access_kpi_threshold_range_user","kpi.threshold.range.user","model_kpi_threshold_range","base.group_user",1,0,0,0
"access_kpi_manager","kpi.manager","model_kpi","kpi.group_kpi_manager",1,1,1,1
"access_kpi_history_manager","kpi.history.user","model_kpi_history","kpi.group_kpi_manager",1,1,1,1
"access_kpi_category_manager","kpi.category.manager","model_kpi_category","kpi.group_kpi_manager",1,1,1,1
"access_kpi_threshold_manager","kpi.threshold.manager","model_kpi_threshold","kpi.group_kpi_manager",1,1,1,1
"access_kpi_threshold_range_manager","kpi.threshold.range.manager","model_kpi_threshold_range","kpi.group_kpi_manager",1,1,1,1
"access_base_external_dbsource_manager","base.external.dbsource.manager","base_external_dbsource.model_base_external_dbsource","base.group_user",1,1,1,1
16 changes: 0 additions & 16 deletions kpi/security/kpi_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@
name="domain_force"
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="kpi_threshold_range_rule">
<field name="name">kpi_threshold_range multi-company</field>
<field name="model_id" ref="model_kpi_threshold_range" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="kpi_threshold_rule">
<field name="name">kpi_threshold multi-company</field>
<field name="model_id" ref="model_kpi_threshold" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="kpi_history_rule">
<field name="name">kpi_history multi-company</field>
<field name="model_id" ref="model_kpi_history" />
Expand Down
Loading

0 comments on commit b5bfd94

Please sign in to comment.