Skip to content

Commit

Permalink
Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
flachica authored and flachica committed Jul 15, 2020
1 parent 227e26d commit adf77e7
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 46 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": "12.0.1.0.0",
"version": "13.0.1.0.0",
"author": "Savoir-faire Linux,Odoo Community Association (OCA)",
"website": "http://www.savoirfairelinux.com",
"license": "AGPL-3",
"category": "Report",
"depends": ["base_external_dbsource", "web_widget_color",],
"depends": ["base_external_dbsource"],
"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 @@ -61,13 +61,13 @@ class KPI(models.Model):
periodicity = fields.Integer("Periodicity", default=1)

periodicity_uom = fields.Selection(
(
[
("minute", "Minute"),
("hour", "Hour"),
("day", "Day"),
("week", "Week"),
("month", "Month"),
),
],
"Periodicity UoM",
required=True,
default="day",
Expand All @@ -80,11 +80,11 @@ class KPI(models.Model):
"Last execution", compute="_compute_display_last_kpi_value",
)
kpi_type = fields.Selection(
(
[
("python", "Python"),
("local", "SQL - Local DB"),
("external", "SQL - External DB"),
),
],
"KPI Computation Type",
)

Expand All @@ -105,10 +105,9 @@ class KPI(models.Model):
default=True,
)
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.user.company_id.id
"res.company", "Company", default=lambda self: self.env.company
)

@api.multi
def _compute_display_last_kpi_value(self):
history_obj = self.env["kpi.history"]
for obj in self:
Expand All @@ -123,7 +122,6 @@ def _compute_display_last_kpi_value(self):
obj.color = "#FFFFFF"
obj.last_execution = False

@api.multi
def _get_kpi_value(self):
self.ensure_one()
kpi_value = 0
Expand Down Expand Up @@ -155,15 +153,13 @@ def _get_kpi_value(self):
res.update({"kpi_id": self.id})
return res

@api.multi
def compute_kpi_value(self):
for obj in self:
history_vals = obj._get_kpi_value()
history_obj = self.env["kpi.history"]
history_obj.sudo().create(history_vals)
return True

@api.multi
def update_next_execution_date(self):
for obj in self:
if obj.periodicity_uom == "hour":
Expand Down
2 changes: 1 addition & 1 deletion kpi/models/kpi_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class KPIHistory(models.Model):
value = fields.Float("Value", required=True, readonly=True)
color = fields.Text("Color", required=True, readonly=True, default="#FFFFFF")
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.user.company_id.id
"res.company", "Company", default=lambda self: self.env.company
)
4 changes: 1 addition & 3 deletions kpi/models/kpi_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class KPIThreshold(models.Model):
_name = "kpi.threshold"
_description = "KPI Threshold"

@api.multi
def _compute_is_valid_threshold(self):
for obj in self:
# check if ranges overlap
Expand Down Expand Up @@ -54,7 +53,7 @@ def _compute_is_valid_threshold(self):
)
kpi_ids = fields.One2many("kpi", "threshold_id", "KPIs")
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.user.company_id.id
"res.company", "Company", default=lambda self: self.env.company
)

@api.model
Expand Down Expand Up @@ -82,7 +81,6 @@ def create(self, data):
range_obj1 = self.env["kpi.threshold.range"]
return super(KPIThreshold, self).create(data)

@api.multi
def get_color(self, kpi_value):
color = "#FFFFFF"
for obj in self:
Expand Down
32 changes: 12 additions & 20 deletions kpi/models/kpi_threshold_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ class KPIThresholdRange(models.Model):
_name = "kpi.threshold.range"
_description = "KPI Threshold Range"

@api.model
def _selection_value_type(self):
return [
("static", "Fixed value"),
("python", "Python Code"),
("local", "SQL - Local DB"),
("external", "SQL - External DB"),
]

name = fields.Char("Name", size=50, required=True)
valid = fields.Boolean(
string="Valid", required=True, compute="_compute_is_valid_range", default=True
Expand All @@ -57,14 +66,7 @@ class KPIThresholdRange(models.Model):
string="Message", size=100, compute="_compute_is_valid_range"
)
min_type = fields.Selection(
(
("static", "Fixed value"),
("python", "Python Code"),
("local", "SQL - Local DB"),
("external", "SQL - Externa DB"),
),
"Min Type",
required=True,
selection="_selection_value_type", string="Min Type", required=True
)
min_value = fields.Float(string="Minimum Value", compute="_compute_min_value")
min_fixed_value = fields.Float("Minimum Fixed Value")
Expand All @@ -74,14 +76,7 @@ class KPIThresholdRange(models.Model):
"base.external.dbsource", "External DB Source Minimum",
)
max_type = fields.Selection(
(
("static", "Fixed value"),
("python", "Python Code"),
("local", "SQL - Local DB"),
("external", "SQL - External DB"),
),
"Max Type",
required=True,
selection="_selection_value_type", string="Max Type", required=True
)
max_value = fields.Float(string="Maximum Value", compute="_compute_max_value")
max_fixed_value = fields.Float("Maximum Fixed Value")
Expand All @@ -101,10 +96,9 @@ class KPIThresholdRange(models.Model):
"Thresholds",
)
company_id = fields.Many2one(
"res.company", "Company", default=lambda self: self.env.user.company_id.id
"res.company", "Company", default=lambda self: self.env.company
)

@api.multi
def _compute_min_value(self):
for obj in self:
value = None
Expand Down Expand Up @@ -134,7 +128,6 @@ def _compute_min_value(self):
obj.min_value = value
obj.min_error = error

@api.multi
def _compute_max_value(self):
for obj in self:
value = None
Expand Down Expand Up @@ -164,7 +157,6 @@ def _compute_max_value(self):
obj.max_value = value
obj.max_error = error

@api.multi
def _compute_is_valid_range(self):
for obj in self:
if obj.min_error or obj.max_error:
Expand Down
3 changes: 3 additions & 0 deletions kpi/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
* Gervais Naoussi <[email protected]>
* Iván Todorovich <[email protected]>
* Adrià Gil <[email protected]>
* `Guadaltech <https://www.guadaltech.es>`_:

* Fernando La Chica <[email protected]>
8 changes: 4 additions & 4 deletions kpi/security/kpi_security.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
>['|',('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','child_of',[user.company_id.id])]</field>
>['|',('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','child_of',[user.company_id.id])]</field>
>['|',('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" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
</data>
</odoo>
4 changes: 2 additions & 2 deletions kpi/tests/test_kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def test_invalid_threshold(self):
)

threshold1 = self.env["kpi.threshold"].create(
{"name": "Threshold1", "range_ids": [(6, 0, [range1.id, range2.id])],}
{"name": "Threshold1", "range_ids": [(6, 0, [range1.id, range2.id])]}
)

threshold2 = self.env["kpi.threshold"].create(
{"name": "Threshold1", "range_ids": [(6, 0, [range3.id, range2.id])],}
{"name": "Threshold1", "range_ids": [(6, 0, [range3.id, range2.id])]}
)

threshold3 = self.env["kpi.threshold"].create(
Expand Down
1 change: 0 additions & 1 deletion kpi/views/kpi_category_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<record model="ir.actions.act_window" id="open_category_list">
<field name="name">Categories</field>
<field name="res_model">kpi.category</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_kpi_category_tree" />
</record>
Expand Down
1 change: 0 additions & 1 deletion kpi/views/kpi_threshold_range_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<record model="ir.actions.act_window" id="open_threshold_range_list">
<field name="name">Ranges</field>
<field name="res_model">kpi.threshold.range</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_kpi_threshold_range_tree" />
</record>
Expand Down
1 change: 0 additions & 1 deletion kpi/views/kpi_threshold_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<record model="ir.actions.act_window" id="open_threshold_list">
<field name="name">Thresholds</field>
<field name="res_model">kpi.threshold</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_kpi_threshold_tree" />
</record>
Expand Down
2 changes: 0 additions & 2 deletions kpi/views/kpi_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
<record model="ir.actions.act_window" id="open_kpi_dashboard">
<field name="name">KPI Dashboard</field>
<field name="res_model">kpi</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,form</field>
<field name="search_view_id" ref="view_kpi_filter" />
</record>
Expand All @@ -155,7 +154,6 @@
<record model="ir.actions.act_window" id="open_kpi_list">
<field name="name">KPI Maintenance</field>
<field name="res_model">kpi</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="view_kpi_filter" />
</record>
Expand Down
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
server-tools
server-backend
1 change: 1 addition & 0 deletions setup/kpi/odoo/addons/kpi
6 changes: 6 additions & 0 deletions setup/kpi/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit adf77e7

Please sign in to comment.