Skip to content

Commit 26b005c

Browse files
committed
[MIG] kpi: Migration to 17.0
1 parent 2c90170 commit 26b005c

15 files changed

+84
-91
lines changed

kpi/__manifest__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
{
55
"name": "Key Performance Indicator",
6-
"version": "13.0.1.0.1",
6+
"version": "17.0.1.0.0",
77
"author": "Savoir-faire Linux,Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/reporting-engine",
99
"license": "AGPL-3",
1010
"category": "Report",
11-
"depends": ["base_external_dbsource"],
11+
"depends": ["base_external_dbsource", "spreadsheet_dashboard"],
1212
"data": [
1313
"security/kpi_security.xml",
1414
"security/ir.model.access.csv",

kpi/models/kpi.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
def is_one_value(result):
1818
# check if sql query returns only one value
19-
if type(result) is dict and "value" in result.dictfetchone():
19+
if isinstance(result, dict) and "value" in result.dictfetchone():
2020
return True
21-
elif type(result) is list and "value" in result[0]:
21+
elif isinstance(result, list) and "value" in result[0]:
2222
return True
2323
else:
2424
return False
@@ -54,8 +54,8 @@ class KPI(models.Model):
5454
_name = "kpi"
5555
_description = "Key Performance Indicator"
5656

57-
name = fields.Char("Name", required=True)
58-
description = fields.Text("Description")
57+
name = fields.Char(required=True)
58+
description = fields.Text()
5959
category_id = fields.Many2one(
6060
"kpi.category",
6161
"Category",
@@ -66,7 +66,7 @@ class KPI(models.Model):
6666
"Threshold",
6767
required=True,
6868
)
69-
periodicity = fields.Integer("Periodicity", default=1)
69+
periodicity = fields.Integer(default=1)
7070

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

8484
next_execution_date = fields.Datetime(
8585
"Next execution date",
86-
readonly=True,
8786
)
8887
value = fields.Float(
89-
string="Value",
9088
compute="_compute_display_last_kpi_value",
9189
)
9290
color = fields.Text(
93-
"Color",
9491
compute="_compute_display_last_kpi_value",
9592
)
9693
last_execution = fields.Datetime(
@@ -122,7 +119,6 @@ class KPI(models.Model):
122119
"History",
123120
)
124121
active = fields.Boolean(
125-
"Active",
126122
help=(
127123
"Only active KPIs will be updated by the scheduler based on"
128124
" the periodicity configuration."

kpi/models/kpi_category.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class KPICategory(models.Model):
99

1010
_name = "kpi.category"
1111
_description = "KPI Category"
12-
name = fields.Char("Name", size=50, required=True)
13-
description = fields.Text("Description")
12+
name = fields.Char(required=True)
13+
description = fields.Text()

kpi/models/kpi_history.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class KPIHistory(models.Model):
1212
_order = "date desc"
1313

1414
name = fields.Char(
15-
"Name",
1615
size=150,
1716
required=True,
1817
default=fields.Datetime.now(),
@@ -21,11 +20,10 @@ class KPIHistory(models.Model):
2120
date = fields.Datetime(
2221
"Execution Date",
2322
required=True,
24-
readonly=True,
2523
default=lambda r: fields.Datetime.now(),
2624
)
27-
value = fields.Float("Value", required=True, readonly=True)
28-
color = fields.Text("Color", required=True, readonly=True, default="#FFFFFF")
25+
value = fields.Float(required=True)
26+
color = fields.Text(required=True, default="#FFFFFF")
2927
company_id = fields.Many2one(
3028
"res.company", "Company", default=lambda self: self.env.company
3129
)

kpi/models/kpi_threshold.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _compute_is_valid_threshold(self):
3434
"Please make sure your ranges do not overlap."
3535
)
3636

37-
name = fields.Char("Name", size=50, required=True)
37+
name = fields.Char(required=True)
3838
range_ids = fields.Many2many(
3939
"kpi.threshold.range",
4040
"kpi_threshold_range_rel",
@@ -43,7 +43,6 @@ def _compute_is_valid_threshold(self):
4343
"Ranges",
4444
)
4545
valid = fields.Boolean(
46-
string="Valid",
4746
required=True,
4847
compute="_compute_is_valid_threshold",
4948
default=True,
@@ -63,10 +62,11 @@ def create(self, data):
6362
range_obj1 = self.env["kpi.threshold.range"]
6463
range_obj2 = self.env["kpi.threshold.range"]
6564
if data.get("range_ids"):
66-
for range1 in data["range_ids"][0][2]:
67-
range_obj1 = range_obj1.browse(range1)
68-
for range2 in data["range_ids"][0][2]:
69-
range_obj2 = range_obj2.browse(range2)
65+
for range1 in data["range_ids"]:
66+
range_obj1 = range_obj1.browse(range1[1])
67+
for range2 in data["range_ids"]:
68+
range_obj2 = range_obj2.browse(range2[1])
69+
7070
if (
7171
range_obj1.valid
7272
and range_obj2.valid
@@ -79,7 +79,7 @@ def create(self, data):
7979
)
8080
range_obj2 = self.env["kpi.threshold.range"]
8181
range_obj1 = self.env["kpi.threshold.range"]
82-
return super(KPIThreshold, self).create(data)
82+
return super().create(data)
8383

8484
def get_color(self, kpi_value):
8585
color = "#FFFFFF"

kpi/models/kpi_threshold_range.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
def is_one_value(result):
1111
# check if sql query returns only one value
12-
if type(result) is dict and "value" in result.dictfetchone():
12+
if isinstance(result, dict) and "value" in result.dictfetchone():
1313
return True
14-
elif type(result) is list and "value" in result[0]:
14+
elif isinstance(result, list) and "value" in result[0]:
1515
return True
1616
else:
1717
return False
@@ -58,16 +58,14 @@ def _selection_value_type(self):
5858
("external", "SQL - External DB"),
5959
]
6060

61-
name = fields.Char("Name", size=50, required=True)
61+
name = fields.Char(required=True)
6262
valid = fields.Boolean(
63-
string="Valid", required=True, compute="_compute_is_valid_range", default=True
63+
required=True, compute="_compute_is_valid_range", default=True
6464
)
6565
invalid_message = fields.Char(
6666
string="Message", size=100, compute="_compute_is_valid_range"
6767
)
68-
min_type = fields.Selection(
69-
selection="_selection_value_type", string="Min Type", required=True
70-
)
68+
min_type = fields.Selection(selection="_selection_value_type", required=True)
7169
min_value = fields.Float(string="Minimum Value", compute="_compute_min_value")
7270
min_fixed_value = fields.Float("Minimum Fixed Value")
7371
min_code = fields.Text("Minimum Computation Code")
@@ -76,9 +74,7 @@ def _selection_value_type(self):
7674
"base.external.dbsource",
7775
"External DB Source Minimum",
7876
)
79-
max_type = fields.Selection(
80-
selection="_selection_value_type", string="Max Type", required=True
81-
)
77+
max_type = fields.Selection(selection="_selection_value_type", required=True)
8278
max_value = fields.Float(string="Maximum Value", compute="_compute_max_value")
8379
max_fixed_value = fields.Float("Maximum Fixed Value")
8480
max_code = fields.Text("Maximum Computation Code")
@@ -88,7 +84,7 @@ def _selection_value_type(self):
8884
"External DB Source Maximum",
8985
)
9086

91-
color = fields.Char(string="Color", help="Choose your color")
87+
color = fields.Char(help="Choose your color")
9288

9389
threshold_ids = fields.Many2many(
9490
"kpi.threshold",

kpi/static/description/icon.png

15.6 KB
Loading

kpi/static/description/icon.svg

+1
Loading

kpi/tests/test_kpi.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55

66
class TestKPI(TransactionCase):
7-
def setUp(self):
8-
super(TestKPI, self).setUp()
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
910

1011
def test_invalid_threshold_range(self):
1112
range1 = self.env["kpi.threshold.range"].create(

kpi/views/kpi_category_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<field name="name">kpi.category.tree</field>
88
<field name="model">kpi.category</field>
99
<field name="arch" type="xml">
10-
<tree string="Categories">
10+
<tree>
1111
<field name="name" />
1212
</tree>
1313
</field>

kpi/views/kpi_history_views.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<field name="name">kpi.history.tree</field>
88
<field name="model">kpi.history</field>
99
<field name="arch" type="xml">
10-
<tree string="KPI History">
10+
<tree>
1111
<field name="name" />
12-
<field name="date" />
13-
<field name="value" />
14-
<field name="color" widget="color" />
12+
<field name="date" readonly="1" />
13+
<field name="value" readonly="1" />
14+
<field name="color" widget="color" readonly="1" />
1515
<field name="company_id" groups="base.group_multi_company" />
1616
</tree>
1717
</field>
@@ -25,9 +25,9 @@
2525
<group col="4" colspan="4">
2626
<field name="kpi_id" />
2727
<field name="name" />
28-
<field name="date" />
29-
<field name="value" />
30-
<field name="color" widget="color" />
28+
<field name="date" readonly="1" />
29+
<field name="value" readonly="1" />
30+
<field name="color" widget="color" readonly="1" />
3131
<field name="company_id" groups="base.group_multi_company" />
3232
</group>
3333
</sheet>

kpi/views/kpi_threshold_range_views.xml

+12-20
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<field name="name">kpi.threshold.range.tree</field>
88
<field name="model">kpi.threshold.range</field>
99
<field name="arch" type="xml">
10-
<tree string="Ranges" decoration-danger="invalid_message">
10+
<tree decoration-danger="invalid_message">
1111
<field name="name" />
1212
<field name="min_value" />
1313
<field name="max_value" />
14-
<field name="color" widget="color" />
14+
<field name="color" widget="color" readonly="1" />
1515
<field name="invalid_message" />
1616
<field name="company_id" groups="base.group_multi_company" />
1717
</tree>
@@ -39,63 +39,55 @@
3939
<field
4040
name="min_fixed_value"
4141
colspan="3"
42-
attrs="{'invisible' : [('min_type', '!=', 'static')]}"
42+
invisible="min_type != 'static'"
4343
/>
4444
<field
4545
name="min_dbsource_id"
46+
invisible="min_type != 'external'"
4647
colspan="3"
47-
attrs="{'invisible' : [('min_type', '!=', 'external')]}"
4848
/>
4949
<field
5050
name="min_code"
5151
colspan="6"
52-
attrs="{'invisible' : [('min_type', 'not in', ('local','external','python'))]}"
53-
/>
54-
<field
55-
name="min_error"
56-
colspan="6"
57-
attrs="{'invisible': [('min_error', '=', False)]}"
52+
invisible="min_type not in ('local', 'external', 'python')"
5853
/>
54+
<field name="min_error" colspan="6" invisible="not min_error" />
5955
<newline />
6056
<separator string="Maximum" />
6157
<newline />
6258
<field name="max_type" colspan="3" />
6359
<field
6460
name="max_fixed_value"
6561
colspan="3"
66-
attrs="{'invisible' : [('max_type', '!=', 'static')]}"
62+
invisible="max_type != 'static'"
6763
/>
6864
<field
6965
name="max_dbsource_id"
7066
colspan="3"
71-
attrs="{'invisible' : [('max_type', '!=', 'external')]}"
67+
invisible="max_type != 'external'"
7268
/>
7369
<newline />
7470
<field
7571
name="max_code"
7672
colspan="6"
77-
attrs="{'invisible' : [('max_type', 'not in', ('local','external','python'))]}"
73+
invisible="max_type not in ('local', 'external', 'python')"
7874
/>
7975
<newline />
80-
<field
81-
name="max_error"
82-
colspan="6"
83-
attrs="{'invisible': [('max_error', '=', False)]}"
84-
/>
76+
<field name="max_error" colspan="6" invisible="not max_error" />
8577
<newline />
8678
</group>
8779
<group col="6" colspan="6">
8880
<separator string="Thresholds" colspan="4" />
8981
<field name="threshold_ids" nolabel="1" colspan="4" />
9082
<separator
9183
string="Errors"
92-
attrs="{'invisible' : [('invalid_message', '=', False)]}"
84+
invisible="not invalid_message"
9385
colspan="4"
9486
/>
9587
<field
9688
name="invalid_message"
9789
nolabel="1"
98-
attrs="{'invisible' : [('invalid_message', '=', False)]}"
90+
invisible="not invalid_message"
9991
colspan="4"
10092
/>
10193
</group>

kpi/views/kpi_threshold_views.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<field name="name">kpi.threshold.tree</field>
88
<field name="model">kpi.threshold</field>
99
<field name="arch" type="xml">
10-
<tree string="Thresholds" decoration-danger="invalid_message">
10+
<tree decoration-danger="invalid_message">
1111
<field name="name" />
1212
<field name="invalid_message" />
1313
<field name="company_id" groups="base.group_multi_company" />
@@ -38,13 +38,13 @@
3838
<newline />
3939
<separator
4040
string="Errors"
41-
attrs="{'invisible' : [('invalid_message', '=', False)]}"
41+
invisible="not invalid_message"
4242
colspan="4"
4343
/>
4444
<field
4545
name="invalid_message"
4646
nolabel="1"
47-
attrs="{'invisible' : [('invalid_message', '=', False)]}"
47+
invisible="not invalid_message"
4848
colspan="4"
4949
/>
5050
<newline />

0 commit comments

Comments
 (0)