[MIG] kpi: Migration to 17.0

This commit is contained in:
EdgarRetes
2024-11-20 13:56:43 -06:00
parent 2c9017035c
commit 26b005c5c3
15 changed files with 84 additions and 91 deletions

View File

@@ -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",

View File

@@ -16,9 +16,9 @@ _logger = logging.getLogger(__name__)
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
@@ -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",
@@ -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(
[
@@ -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(
@@ -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."

View File

@@ -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()

View File

@@ -12,7 +12,6 @@ class KPIHistory(models.Model):
_order = "date desc"
name = fields.Char(
"Name",
size=150,
required=True,
default=fields.Datetime.now(),
@@ -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
)

View File

@@ -34,7 +34,7 @@ class KPIThreshold(models.Model):
"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",
@@ -43,7 +43,6 @@ class KPIThreshold(models.Model):
"Ranges",
)
valid = fields.Boolean(
string="Valid",
required=True,
compute="_compute_is_valid_threshold",
default=True,
@@ -63,10 +62,11 @@ class KPIThreshold(models.Model):
range_obj1 = self.env["kpi.threshold.range"]
range_obj2 = self.env["kpi.threshold.range"]
if data.get("range_ids"):
for range1 in data["range_ids"][0][2]:
range_obj1 = range_obj1.browse(range1)
for range2 in data["range_ids"][0][2]:
range_obj2 = range_obj2.browse(range2)
for range1 in data["range_ids"]:
range_obj1 = range_obj1.browse(range1[1])
for range2 in data["range_ids"]:
range_obj2 = range_obj2.browse(range2[1])
if (
range_obj1.valid
and range_obj2.valid
@@ -79,7 +79,7 @@ class KPIThreshold(models.Model):
)
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"

View File

@@ -9,9 +9,9 @@ from odoo.tools.safe_eval import safe_eval
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
@@ -58,16 +58,14 @@ class KPIThresholdRange(models.Model):
("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")
@@ -76,9 +74,7 @@ class KPIThresholdRange(models.Model):
"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")
@@ -88,7 +84,7 @@ class KPIThresholdRange(models.Model):
"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",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 141.43 140.62"><defs><style>.cls-1{fill:none;stroke:#1a6f66;stroke-linecap:round;stroke-linejoin:round;stroke-width:6.12px;}.cls-2{fill:#f86226;}.cls-2,.cls-3,.cls-4{stroke-width:0px;}.cls-3{fill:#fff;}.cls-4{fill:#fbb946;}</style></defs><rect class="cls-3" width="141.43" height="140.62" rx="4.99" ry="4.99"/><path class="cls-4" d="M101.13,47.99c-6.46-10.65-18.01-17.33-31.35-17.33-19.09,0-34.84,14.6-36.66,33.22h-6.93c-1.11,0-1.8,1.2-1.25,2.16l5.18,8.96,5.18,8.96c.55.96,1.94.96,2.49,0l5.18-8.96,5.18-8.96c.55-.96-.14-2.16-1.25-2.16h-6.52c1.79-14.64,14.29-26.02,29.41-26.02,11.99,0,22.34,7.15,27,17.41"/><path class="cls-2" d="M38.28,87.17c6.53,10.36,18.07,17.26,31.2,17.26,19.09,0,34.84-14.6,36.66-33.22h6.93c1.11,0,1.8-1.2,1.25-2.16l-5.18-8.96-5.18-8.96c-.55-.96-1.94-.96-2.49,0l-5.18,8.96-5.18,8.96c-.55.96.14,2.16,1.25,2.16h6.52c-1.79,14.64-14.29,26.02-29.41,26.02-11.86,0-22.11-7-26.85-17.08"/><polyline class="cls-1" points="56.68 69.36 66.62 78.85 83.8 53.08"/></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -4,8 +4,9 @@ from odoo.tests.common import TransactionCase
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(

View File

@@ -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>

View File

@@ -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>
@@ -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>

View File

@@ -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>
@@ -39,23 +39,19 @@
<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 />
@@ -63,25 +59,21 @@
<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">
@@ -89,13 +81,13 @@
<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>

View File

@@ -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" />
@@ -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 />

View File

@@ -8,9 +8,9 @@
<field name="model">kpi</field>
<field eval="8" name="priority" />
<field name="arch" type="xml">
<tree string="Key Performance Indicators">
<tree>
<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" />
@@ -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">
@@ -41,7 +41,7 @@
t-attf-style="color:#{record.color.raw_value}"
>
<strong>
<field name="value" />
<field name="value" readonly="1" />
</strong>
</div>
<div
@@ -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"
@@ -115,20 +115,27 @@
<field name="history_ids" readonly="1" nolabel="1" />
</page>
<page string="Computation" groups="kpi.group_kpi_manager">
<group col="6">
<field name="periodicity" colspan="3" />
<field name="periodicity_uom" colspan="3" />
<field name="next_execution_date" colspan="3" />
<separator string="KPI Computation" colspan="6" />
<newline />
<field name="kpi_type" colspan="2" />
<field
name="dbsource_id"
colspan="2"
attrs="{'invisible' : [('kpi_type', '!=', 'external')]}"
/>
<newline />
<field name="kpi_code" colspan="6" />
<field name="kpi_type" invisible="1" />
<group>
<group>
<field name="periodicity" />
<field name="next_execution_date" readonly="1" />
</group>
<group>
<field name="periodicity_uom" />
</group>
</group>
<group string="KPI Computation">
<group>
<field name="kpi_type" />
<field
name="dbsource_id"
invisible="kpi_type != 'external'"
/>
</group>
<group>
<field name="kpi_code" />
</group>
</group>
</page>
<page string="Description">
@@ -152,7 +159,7 @@
<field name="act_window_id" ref="open_kpi_dashboard" />
</record>
<record model="ir.actions.act_window" id="open_kpi_list">
<field name="name">KPI Maintenance</field>
<field name="name">KPI</field>
<field name="res_model">kpi</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="view_kpi_filter" />

View File

@@ -2,19 +2,21 @@
<!-- Copyright 2012 - Now Savoir-faire Linux <https://www.savoirfairelinux.com/>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<!-- Change parent-->
<menuitem
id="menu_kpi_dasboard"
name="Key Performance Indicators"
action="open_kpi_dashboard"
sequence="15"
parent="base.menu_reporting_dashboard"
parent="spreadsheet_dashboard.spreadsheet_dashboard_menu_dashboard"
groups="base.group_user"
/>
<!-- CONFIGURATION -->
<!-- Change parent-->
<menuitem
id="menu_configuration_kpi"
parent="spreadsheet_dashboard.spreadsheet_dashboard_menu_configuration"
name="Key Performance Indicators"
parent="base.menu_reporting_config"
groups="kpi.group_kpi_manager"
sequence="10"
/>