Browse Source

[IMP] kpi: Add Kanban Views. Improve python code, Allow to access Odoo

pull/267/head
Enric Tobella 6 years ago
committed by Adrià Gil Sorribes
parent
commit
5764f2464e
  1. 15
      kpi/__manifest__.py
  2. 0
      kpi/data/kpi_data.xml
  3. 12
      kpi/models/kpi.py
  4. 2
      kpi/models/kpi_history.py
  5. 8
      kpi/security/ir.model.access.csv
  6. 7
      kpi/security/kpi_security.xml
  7. 0
      kpi/views/kpi_category_views.xml
  8. 0
      kpi/views/kpi_history_views.xml
  9. 0
      kpi/views/kpi_threshold_range_views.xml
  10. 0
      kpi/views/kpi_threshold_views.xml
  11. 68
      kpi/views/kpi_views.xml
  12. 31
      kpi/views/menu.xml

15
kpi/__manifest__.py

@ -10,17 +10,18 @@
"category": "Report", "category": "Report",
"depends": [ "depends": [
'base_external_dbsource', 'base_external_dbsource',
'web_widget_color',
], ],
"data": [ "data": [
'security/ir.model.access.csv',
'security/kpi_security.xml', 'security/kpi_security.xml',
'views/kpi_category.xml',
'views/kpi_history.xml',
'views/kpi_threshold_range.xml',
'views/kpi_threshold.xml',
'views/kpi.xml',
'security/ir.model.access.csv',
'views/kpi_category_views.xml',
'views/kpi_history_views.xml',
'views/kpi_threshold_range_views.xml',
'views/kpi_threshold_views.xml',
'views/kpi_views.xml',
'views/menu.xml', 'views/menu.xml',
'data/kpi.xml',
'data/kpi_data.xml',
], ],
"images": [ "images": [
"images/kpi_definition.png", "images/kpi_definition.png",

0
kpi/data/kpi.xml → kpi/data/kpi_data.xml

12
kpi/models/kpi.py

@ -74,6 +74,9 @@ class KPI(models.Model):
value = fields.Float(string='Value', value = fields.Float(string='Value',
compute="_compute_display_last_kpi_value", compute="_compute_display_last_kpi_value",
) )
color = fields.Text('Color', compute="_compute_display_last_kpi_value",)
last_execution = fields.Datetime(
'Last execution', compute="_compute_display_last_kpi_value",)
kpi_type = fields.Selection(( kpi_type = fields.Selection((
('python', 'Python'), ('python', 'Python'),
('local', 'SQL - Local DB'), ('local', 'SQL - Local DB'),
@ -109,9 +112,14 @@ class KPI(models.Model):
for obj in self: for obj in self:
history_ids = history_obj.search([("kpi_id", "=", obj.id)]) history_ids = history_obj.search([("kpi_id", "=", obj.id)])
if history_ids: if history_ids:
obj.value = obj.history_ids[0].value
his = obj.history_ids[0]
obj.value = his.value
obj.color = his.color
obj.last_execution = his.date
else: else:
obj.value = 0 obj.value = 0
obj.color = '#FFFFFF'
obj.last_execution = False
@api.multi @api.multi
def compute_kpi_value(self): def compute_kpi_value(self):
@ -131,7 +139,7 @@ class KPI(models.Model):
if is_one_value(res): if is_one_value(res):
kpi_value = res[0]['value'] kpi_value = res[0]['value']
elif obj.kpi_type == 'python': elif obj.kpi_type == 'python':
kpi_value = safe_eval(obj.kpi_code)
kpi_value = safe_eval(obj.kpi_code, {'self': obj})
threshold_obj = obj.threshold_id threshold_obj = obj.threshold_id
values = { values = {

2
kpi/models/kpi_history.py

@ -18,7 +18,7 @@ class KPIHistory(models.Model):
'Execution Date', 'Execution Date',
required=True, required=True,
readonly=True, readonly=True,
default=fields.Datetime.now()
default=lambda r: fields.Datetime.now()
) )
value = fields.Float('Value', required=True, readonly=True) value = fields.Float('Value', required=True, readonly=True)
color = fields.Text('Color', required=True, color = fields.Text('Color', required=True,

8
kpi/security/ir.model.access.csv

@ -4,8 +4,8 @@
"access_kpi_category_user","kpi.category.user","model_kpi_category","base.group_user",1,0,0,0 "access_kpi_category_user","kpi.category.user","model_kpi_category","base.group_user",1,0,0,0
"access_kpi_threshold_user","kpi.threshold.user","model_kpi_threshold","base.group_user",1,0,0,0 "access_kpi_threshold_user","kpi.threshold.user","model_kpi_threshold","base.group_user",1,0,0,0
"access_kpi_threshold_range_user","kpi.threshold.range.user","model_kpi_threshold_range","base.group_user",1,0,0,0 "access_kpi_threshold_range_user","kpi.threshold.range.user","model_kpi_threshold_range","base.group_user",1,0,0,0
"access_kpi_manager","kpi.manager","model_kpi","base.group_user",1,1,1,1
"access_kpi_category_manager","kpi.category.manager","model_kpi_category","base.group_user",1,1,1,1
"access_kpi_threshold_manager","kpi.threshold.manager","model_kpi_threshold","base.group_user",1,1,1,1
"access_kpi_threshold_range_manager","kpi.threshold.range.manager","model_kpi_threshold_range","base.group_user",1,1,1,1
"access_kpi_manager","kpi.manager","model_kpi","kpi.group_kpi_manager",1,1,1,1
"access_kpi_category_manager","kpi.category.manager","model_kpi_category","kpi.group_kpi_manager",1,1,1,1
"access_kpi_threshold_manager","kpi.threshold.manager","model_kpi_threshold","kpi.group_kpi_manager",1,1,1,1
"access_kpi_threshold_range_manager","kpi.threshold.range.manager","model_kpi_threshold_range","kpi.group_kpi_manager",1,1,1,1
"access_base_external_dbsource_manager","base.external.dbsource.manager","base_external_dbsource.model_base_external_dbsource","base.group_user",1,1,1,1 "access_base_external_dbsource_manager","base.external.dbsource.manager","base_external_dbsource.model_base_external_dbsource","base.group_user",1,1,1,1

7
kpi/security/kpi_security.xml

@ -3,6 +3,13 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<data noupdate="0">
<record id="group_kpi_manager" model="res.groups">
<field name="name">Manage KPI's</field>
<field name="category_id" ref="base.module_category_hidden"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
<data noupdate="1"> <data noupdate="1">
<!-- Rule --> <!-- Rule -->

0
kpi/views/kpi_category.xml → kpi/views/kpi_category_views.xml

0
kpi/views/kpi_history.xml → kpi/views/kpi_history_views.xml

0
kpi/views/kpi_threshold_range.xml → kpi/views/kpi_threshold_range_views.xml

0
kpi/views/kpi_threshold.xml → kpi/views/kpi_threshold_views.xml

68
kpi/views/kpi.xml → kpi/views/kpi_views.xml

@ -6,6 +6,7 @@
<record id="view_kpi_tree" model="ir.ui.view"> <record id="view_kpi_tree" model="ir.ui.view">
<field name="name">kpi.tree</field> <field name="name">kpi.tree</field>
<field name="model">kpi</field> <field name="model">kpi</field>
<field eval="8" name="priority"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Key Performance Indicators"> <tree string="Key Performance Indicators">
<field name="name"/> <field name="name"/>
@ -16,6 +17,33 @@
</tree> </tree>
</field> </field>
</record> </record>
<record id="view_kpi_kanban" model="ir.ui.view">
<field name="name">kpi.kanban</field>
<field name="model">kpi</field>
<field name="arch" type="xml">
<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="last_execution"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click o_kpi_kanban">
<div class="oe_kanban_details">
<div class="o_kanban_record_title oe_partner_heading"><strong><field name="display_name"/></strong></div>
<div class="o_kanban_tags_section oe_kanban_partner_categories" t-attf-style="color:#{record.color.raw_value}">
<strong><field name="value"/></strong>
</div><div class="o_kanban_tags_section oe_kanban_partner_categories">
<field name="last_execution"/>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
<record id="view_kpi_filter" model="ir.ui.view"> <record id="view_kpi_filter" model="ir.ui.view">
<field name="name">kpi.filter</field> <field name="name">kpi.filter</field>
@ -57,15 +85,20 @@
<group> <group>
<field name="value" colspan="2"/> <field name="value" colspan="2"/>
<field name="active" colspan="2"/> <field name="active" colspan="2"/>
<field name="company_id" groups="base.group_multi_company"/>
<button name="compute_kpi_value" string="Compute KPI Now" colspan="2" type="object"/>
<field name="company_id"
groups="base.group_multi_company"/>
<button name="compute_kpi_value"
string="Compute KPI Now"
colspan="2"
type="object"
groups="kpi.group_kpi_manager"/>
</group> </group>
</group> </group>
<notebook colspan="6"> <notebook colspan="6">
<page string="History"> <page string="History">
<field name="history_ids" readonly="1" nolabel="1"/> <field name="history_ids" readonly="1" nolabel="1"/>
</page> </page>
<page string="Computation">
<page string="Computation" groups="kpi.group_kpi_manager">
<group col="6"> <group col="6">
<field name="periodicity" colspan="3"/> <field name="periodicity" colspan="3"/>
<field name="periodicity_uom" colspan="3"/> <field name="periodicity_uom" colspan="3"/>
@ -73,7 +106,8 @@
<separator string="KPI Computation" colspan="6"/> <separator string="KPI Computation" colspan="6"/>
<newline/> <newline/>
<field name="kpi_type" colspan="2"/> <field name="kpi_type" colspan="2"/>
<field name="dbsource_id" colspan="2" attrs="{'invisible' : [('kpi_type', '!=', 'external')]}"/>
<field name="dbsource_id" colspan="2"
attrs="{'invisible' : [('kpi_type', '!=', 'external')]}"/>
<newline/> <newline/>
<field name="kpi_code" colspan="6"/> <field name="kpi_code" colspan="6"/>
</group> </group>
@ -87,12 +121,34 @@
</field> </field>
</record> </record>
<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>
<record id="action_view_kpi_kanban" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">kanban</field>
<field name="view_id" ref="view_kpi_kanban"/>
<field name="act_window_id" ref="open_kpi_dashboard"/>
</record>
<record model="ir.actions.act_window" id="open_kpi_list"> <record model="ir.actions.act_window" id="open_kpi_list">
<field name="name">Key Performance Indicators</field>
<field name="name">KPI Maintenance</field>
<field name="res_model">kpi</field> <field name="res_model">kpi</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="view_id" ref="view_kpi_tree"/>
<field name="search_view_id" ref="view_kpi_filter"/> <field name="search_view_id" ref="view_kpi_filter"/>
</record> </record>
<record id="action_view_kpi_tree" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_kpi_tree"/>
<field name="act_window_id" ref="open_kpi_list"/>
</record>
</odoo> </odoo>

31
kpi/views/menu.xml

@ -3,44 +3,47 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<menuitem id="menu_reporting_kpi"
name="KPI"
action="open_kpi_list"
<menuitem id="menu_kpi_dasboard"
name="Key Performance Indicators"
action="open_kpi_dashboard"
sequence="15" sequence="15"
parent="base.menu_reporting_dashboard" parent="base.menu_reporting_dashboard"
groups="base.group_user"/> groups="base.group_user"/>
<!-- CONFIGURATION -->
<menuitem id="menu_configuration_kpi" <menuitem id="menu_configuration_kpi"
name="KPI"
name="Key Performance Indicators"
parent="base.menu_reporting_config" parent="base.menu_reporting_config"
groups="base.group_user"
sequence="20"/>
groups="kpi.group_kpi_manager"
sequence="10"/>
<menuitem id="menu_configuration_kpi_kpi"
name="Key Performance Indicators"
action="open_kpi_list"
sequence="10"
parent="menu_configuration_kpi"/>
<menuitem id="menu_configuration_kpi_category" <menuitem id="menu_configuration_kpi_category"
name="Categories" name="Categories"
action="open_category_list" action="open_category_list"
parent="menu_configuration_kpi" parent="menu_configuration_kpi"
groups="base.group_user"
sequence="10"/>
sequence="20"/>
<menuitem id="menu_configuration_kpi_range" <menuitem id="menu_configuration_kpi_range"
name="Ranges" name="Ranges"
action="open_threshold_range_list" action="open_threshold_range_list"
parent="menu_configuration_kpi" parent="menu_configuration_kpi"
groups="base.group_user"
sequence="20"/>
sequence="30"/>
<menuitem id="menu_configuration_kpi_dbsource" <menuitem id="menu_configuration_kpi_dbsource"
name="Data Sources" name="Data Sources"
action="base_external_dbsource.action_dbsource" action="base_external_dbsource.action_dbsource"
parent="menu_configuration_kpi" parent="menu_configuration_kpi"
groups="base.group_user"
sequence="20"/>
sequence="40"/>
<menuitem id="menu_configuration_kpi_threshold" <menuitem id="menu_configuration_kpi_threshold"
name="Thresholds" name="Thresholds"
action="open_threshold_list" action="open_threshold_list"
parent="menu_configuration_kpi" parent="menu_configuration_kpi"
groups="base.group_user"
sequence="10"/>
sequence="50"/>
</odoo> </odoo>
Loading…
Cancel
Save