Skip to content

Commit

Permalink
[MIG] kpi: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarRetes committed Nov 26, 2024
1 parent bfbbb76 commit 2d852c3
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 75 deletions.
4 changes: 2 additions & 2 deletions kpi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

{
"name": "Key Performance Indicator",
"version": "13.0.1.0.1",
"version": "17.0.1.0.0",
"author": "Savoir-faire Linux,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"license": "AGPL-3",
"category": "Report",
"depends": ["base_external_dbsource"],
"depends": ["base_external_dbsource", "spreadsheet_dashboard"],
"data": [
"security/kpi_security.xml",
"security/ir.model.access.csv",
Expand Down
14 changes: 5 additions & 9 deletions kpi/models/kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

def is_one_value(result):
# check if sql query returns only one value
if type(result) is dict and "value" in result.dictfetchone():
if isinstance(result, dict) and "value" in result.dictfetchone():
return True
elif type(result) is list and "value" in result[0]:
elif isinstance(result, list) and "value" in result[0]:
return True
else:
return False
Expand Down Expand Up @@ -54,8 +54,8 @@ class KPI(models.Model):
_name = "kpi"
_description = "Key Performance Indicator"

name = fields.Char("Name", required=True)
description = fields.Text("Description")
name = fields.Char(required=True)
description = fields.Text()
category_id = fields.Many2one(
"kpi.category",
"Category",
Expand All @@ -66,7 +66,7 @@ class KPI(models.Model):
"Threshold",
required=True,
)
periodicity = fields.Integer("Periodicity", default=1)
periodicity = fields.Integer(default=1)

periodicity_uom = fields.Selection(
[
Expand All @@ -83,14 +83,11 @@ class KPI(models.Model):

next_execution_date = fields.Datetime(
"Next execution date",
readonly=True,
)
value = fields.Float(
string="Value",
compute="_compute_display_last_kpi_value",
)
color = fields.Text(
"Color",
compute="_compute_display_last_kpi_value",
)
last_execution = fields.Datetime(
Expand Down Expand Up @@ -122,7 +119,6 @@ class KPI(models.Model):
"History",
)
active = fields.Boolean(
"Active",
help=(
"Only active KPIs will be updated by the scheduler based on"
" the periodicity configuration."
Expand Down
4 changes: 2 additions & 2 deletions kpi/models/kpi_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class KPICategory(models.Model):

_name = "kpi.category"
_description = "KPI Category"
name = fields.Char("Name", size=50, required=True)
description = fields.Text("Description")
name = fields.Char(required=True)
description = fields.Text()
6 changes: 2 additions & 4 deletions kpi/models/kpi_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class KPIHistory(models.Model):
_order = "date desc"

name = fields.Char(
"Name",
size=150,
required=True,
default=fields.Datetime.now(),
Expand All @@ -21,11 +20,10 @@ class KPIHistory(models.Model):
date = fields.Datetime(
"Execution Date",
required=True,
readonly=True,
default=lambda r: fields.Datetime.now(),
)
value = fields.Float("Value", required=True, readonly=True)
color = fields.Text("Color", required=True, readonly=True, default="#FFFFFF")
value = fields.Float(required=True)
color = fields.Text(required=True, default="#FFFFFF")
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.company
)
5 changes: 2 additions & 3 deletions kpi/models/kpi_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _compute_is_valid_threshold(self):
"Please make sure your ranges do not overlap."
)

name = fields.Char("Name", size=50, required=True)
name = fields.Char(required=True)
range_ids = fields.Many2many(
"kpi.threshold.range",
"kpi_threshold_range_rel",
Expand All @@ -43,7 +43,6 @@ def _compute_is_valid_threshold(self):
"Ranges",
)
valid = fields.Boolean(
string="Valid",
required=True,
compute="_compute_is_valid_threshold",
default=True,
Expand Down Expand Up @@ -79,7 +78,7 @@ def create(self, data):
)
range_obj2 = self.env["kpi.threshold.range"]
range_obj1 = self.env["kpi.threshold.range"]
return super(KPIThreshold, self).create(data)
return super().create(data)

def get_color(self, kpi_value):
color = "#FFFFFF"
Expand Down
18 changes: 7 additions & 11 deletions kpi/models/kpi_threshold_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

def is_one_value(result):
# check if sql query returns only one value
if type(result) is dict and "value" in result.dictfetchone():
if isinstance(result, dict) and "value" in result.dictfetchone():
return True
elif type(result) is list and "value" in result[0]:
elif isinstance(result, list) and "value" in result[0]:
return True
else:
return False
Expand Down Expand Up @@ -58,16 +58,14 @@ def _selection_value_type(self):
("external", "SQL - External DB"),
]

name = fields.Char("Name", size=50, required=True)
name = fields.Char(required=True)
valid = fields.Boolean(
string="Valid", required=True, compute="_compute_is_valid_range", default=True
required=True, compute="_compute_is_valid_range", default=True
)
invalid_message = fields.Char(
string="Message", size=100, compute="_compute_is_valid_range"
)
min_type = fields.Selection(
selection="_selection_value_type", string="Min Type", required=True
)
min_type = fields.Selection(selection="_selection_value_type", required=True)
min_value = fields.Float(string="Minimum Value", compute="_compute_min_value")
min_fixed_value = fields.Float("Minimum Fixed Value")
min_code = fields.Text("Minimum Computation Code")
Expand All @@ -76,9 +74,7 @@ def _selection_value_type(self):
"base.external.dbsource",
"External DB Source Minimum",
)
max_type = fields.Selection(
selection="_selection_value_type", string="Max Type", required=True
)
max_type = fields.Selection(selection="_selection_value_type", required=True)
max_value = fields.Float(string="Maximum Value", compute="_compute_max_value")
max_fixed_value = fields.Float("Maximum Fixed Value")
max_code = fields.Text("Maximum Computation Code")
Expand All @@ -88,7 +84,7 @@ def _selection_value_type(self):
"External DB Source Maximum",
)

color = fields.Char(string="Color", help="Choose your color")
color = fields.Char(help="Choose your color")

threshold_ids = fields.Many2many(
"kpi.threshold",
Expand Down
5 changes: 3 additions & 2 deletions kpi/tests/test_kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class TestKPI(TransactionCase):
def setUp(self):
super(TestKPI, self).setUp()
@classmethod
def setUpClass(cls):
super().setUpClass()

def test_invalid_threshold_range(self):
range1 = self.env["kpi.threshold.range"].create(
Expand Down
2 changes: 1 addition & 1 deletion kpi/views/kpi_category_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="name">kpi.category.tree</field>
<field name="model">kpi.category</field>
<field name="arch" type="xml">
<tree string="Categories">
<tree>
<field name="name" />
</tree>
</field>
Expand Down
14 changes: 7 additions & 7 deletions kpi/views/kpi_history_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<field name="name">kpi.history.tree</field>
<field name="model">kpi.history</field>
<field name="arch" type="xml">
<tree string="KPI History">
<tree>
<field name="name" />
<field name="date" />
<field name="value" />
<field name="color" widget="color" />
<field name="date" readonly="1" />
<field name="value" readonly="1" />
<field name="color" widget="color" readonly="1" />
<field name="company_id" groups="base.group_multi_company" />
</tree>
</field>
Expand All @@ -25,9 +25,9 @@
<group col="4" colspan="4">
<field name="kpi_id" />
<field name="name" />
<field name="date" />
<field name="value" />
<field name="color" widget="color" />
<field name="date" readonly="1" />
<field name="value" readonly="1" />
<field name="color" widget="color" readonly="1" />
<field name="company_id" groups="base.group_multi_company" />
</group>
</sheet>
Expand Down
34 changes: 13 additions & 21 deletions kpi/views/kpi_threshold_range_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<field name="name">kpi.threshold.range.tree</field>
<field name="model">kpi.threshold.range</field>
<field name="arch" type="xml">
<tree string="Ranges" decoration-danger="invalid_message">
<tree decoration-danger="invalid_message">
<field name="name" />
<field name="min_value" />
<field name="max_value" />
<field name="color" widget="color" />
<field name="color" widget="color" readonly="1" />
<field name="invalid_message" />
<field name="company_id" groups="base.group_multi_company" />
</tree>
Expand All @@ -25,7 +25,7 @@
<sheet>
<group col="6" colspan="6">
<field name="name" colspan="2" />
<field name="color" colspan="2" widget="color" />
<field name="color" colspan="2" widget="color" readonly="1" />
<field
name="company_id"
groups="base.group_multi_company"
Expand All @@ -39,63 +39,55 @@
<field
name="min_fixed_value"
colspan="3"
attrs="{'invisible' : [('min_type', '!=', 'static')]}"
invisible="min_type != 'static'"
/>
<field
name="min_dbsource_id"
invisible="min_type != 'external'"
colspan="3"
attrs="{'invisible' : [('min_type', '!=', 'external')]}"
/>
<field
name="min_code"
colspan="6"
attrs="{'invisible' : [('min_type', 'not in', ('local','external','python'))]}"
/>
<field
name="min_error"
colspan="6"
attrs="{'invisible': [('min_error', '=', False)]}"
invisible="min_type not in ('local', 'external', 'python')"
/>
<field name="min_error" colspan="6" invisible="not min_error" />
<newline />
<separator string="Maximum" />
<newline />
<field name="max_type" colspan="3" />
<field
name="max_fixed_value"
colspan="3"
attrs="{'invisible' : [('max_type', '!=', 'static')]}"
invisible="max_type != 'static'"
/>
<field
name="max_dbsource_id"
colspan="3"
attrs="{'invisible' : [('max_type', '!=', 'external')]}"
invisible="max_type != 'external'"
/>
<newline />
<field
name="max_code"
colspan="6"
attrs="{'invisible' : [('max_type', 'not in', ('local','external','python'))]}"
invisible="max_type not in ('local', 'external', 'python')"
/>
<newline />
<field
name="max_error"
colspan="6"
attrs="{'invisible': [('max_error', '=', False)]}"
/>
<field name="max_error" colspan="6" invisible="not max_error" />
<newline />
</group>
<group col="6" colspan="6">
<separator string="Thresholds" colspan="4" />
<field name="threshold_ids" nolabel="1" colspan="4" />
<separator
string="Errors"
attrs="{'invisible' : [('invalid_message', '=', False)]}"
invisible="not invalid_message"
colspan="4"
/>
<field
name="invalid_message"
nolabel="1"
attrs="{'invisible' : [('invalid_message', '=', False)]}"
invisible="not invalid_message"
colspan="4"
/>
</group>
Expand Down
6 changes: 3 additions & 3 deletions kpi/views/kpi_threshold_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="name">kpi.threshold.tree</field>
<field name="model">kpi.threshold</field>
<field name="arch" type="xml">
<tree string="Thresholds" decoration-danger="invalid_message">
<tree decoration-danger="invalid_message">
<field name="name" />
<field name="invalid_message" />
<field name="company_id" groups="base.group_multi_company" />
Expand Down Expand Up @@ -38,13 +38,13 @@
<newline />
<separator
string="Errors"
attrs="{'invisible' : [('invalid_message', '=', False)]}"
invisible="not invalid_message"
colspan="4"
/>
<field
name="invalid_message"
nolabel="1"
attrs="{'invisible' : [('invalid_message', '=', False)]}"
invisible="not invalid_message"
colspan="4"
/>
<newline />
Expand Down
Loading

0 comments on commit 2d852c3

Please sign in to comment.