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 20, 2024
1 parent bfbbb76 commit daa13f1
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 67 deletions.
2 changes: 1 addition & 1 deletion kpi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"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",
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
4 changes: 2 additions & 2 deletions kpi/tests/test_kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


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

def test_invalid_threshold_range(self):
range1 = self.env["kpi.threshold.range"].create(
Expand Down
12 changes: 6 additions & 6 deletions kpi/views/kpi_history_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<field name="arch" type="xml">
<tree string="KPI History">
<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
32 changes: 12 additions & 20 deletions kpi/views/kpi_threshold_range_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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
4 changes: 2 additions & 2 deletions kpi/views/kpi_threshold_views.xml
Original file line number Diff line number Diff line change
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
19 changes: 12 additions & 7 deletions kpi/views/kpi_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field name="arch" type="xml">
<tree string="Key Performance Indicators">
<field name="name" />
<field name="value" widget="progressbar" />
<field name="value" widget="progressbar" readonly="1" />
<field name="category_id" />
<field name="kpi_type" />
<field name="company_id" groups="base.group_multi_company" />
Expand All @@ -24,8 +24,8 @@
<kanban class="o_kpi_kanban" create="false" edit="false" delete="false">
<field name="id" />
<field name="display_name" />
<field name="color" />
<field name="value" />
<field name="color" readonly="1" />
<field name="value" readonly="1" />
<field name="last_execution" />
<templates>
<t t-name="kanban-box">
Expand All @@ -41,7 +41,7 @@
t-attf-style="color:#{record.color.raw_value}"
>
<strong>
<field name="value" />
<field name="value" readonly="1" />
</strong>
</div>
<div
Expand Down Expand Up @@ -95,7 +95,7 @@
<field name="category_id" />
</group>
<group>
<field name="value" colspan="2" />
<field name="value" colspan="2" readonly="1" />
<field name="active" colspan="2" />
<field
name="company_id"
Expand All @@ -115,17 +115,22 @@
<field name="history_ids" readonly="1" nolabel="1" />
</page>
<page string="Computation" groups="kpi.group_kpi_manager">
<field name="kpi_type" invisible="1" />
<group col="6">
<field name="periodicity" colspan="3" />
<field name="periodicity_uom" colspan="3" />
<field name="next_execution_date" colspan="3" />
<field
name="next_execution_date"
colspan="3"
readonly="1"
/>
<separator string="KPI Computation" colspan="6" />
<newline />
<field name="kpi_type" colspan="2" />
<field
name="dbsource_id"
colspan="2"
attrs="{'invisible' : [('kpi_type', '!=', 'external')]}"
invisible="kpi_type != 'external'"
/>
<newline />
<field name="kpi_code" colspan="6" />
Expand Down

0 comments on commit daa13f1

Please sign in to comment.