|
@ -21,13 +21,13 @@ |
|
|
|
|
|
|
|
|
from dateutil.relativedelta import relativedelta |
|
|
from dateutil.relativedelta import relativedelta |
|
|
from datetime import datetime |
|
|
from datetime import datetime |
|
|
from osv import fields, osv |
|
|
|
|
|
|
|
|
from osv import fields, orm, osv |
|
|
from openerp.tools.translate import _ |
|
|
from openerp.tools.translate import _ |
|
|
import openerp.tools as tools |
|
|
|
|
|
import time |
|
|
import time |
|
|
import logging |
|
|
import logging |
|
|
_logger = logging.getLogger(__name__) |
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_one_value(result): |
|
|
def is_one_value(result): |
|
|
# check if sql query returns only one value |
|
|
# check if sql query returns only one value |
|
|
if type(result) is dict and 'value' in result.dictfetchone(): |
|
|
if type(result) is dict and 'value' in result.dictfetchone(): |
|
@ -37,6 +37,7 @@ def is_one_value(result): |
|
|
else: |
|
|
else: |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_select_query(query): |
|
|
def is_select_query(query): |
|
|
# check if sql query is a SELECT statement |
|
|
# check if sql query is a SELECT statement |
|
|
|
|
|
|
|
@ -45,7 +46,8 @@ def is_select_query(query): |
|
|
return False |
|
|
return False |
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_category(osv.osv): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_category(orm.Model): |
|
|
""" |
|
|
""" |
|
|
KPI Category |
|
|
KPI Category |
|
|
""" |
|
|
""" |
|
@ -56,9 +58,8 @@ class mgmtsystem_kpi_category(osv.osv): |
|
|
'description': fields.text('Description') |
|
|
'description': fields.text('Description') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mgmtsystem_kpi_category() |
|
|
|
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_threshold_range(osv.osv): |
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_threshold_range(orm.Model): |
|
|
""" |
|
|
""" |
|
|
KPI Threshold Range |
|
|
KPI Threshold Range |
|
|
""" |
|
|
""" |
|
@ -137,18 +138,18 @@ class mgmtsystem_kpi_threshold_range(osv.osv): |
|
|
'name': fields.char('Name', size=50, required=True), |
|
|
'name': fields.char('Name', size=50, required=True), |
|
|
'valid': fields.function(_is_valid_range, string='Valid', type='boolean', required=True), |
|
|
'valid': fields.function(_is_valid_range, string='Valid', type='boolean', required=True), |
|
|
'invalid_message': fields.function(_generate_invalid_message, string='Message', type='char', size=100), |
|
|
'invalid_message': fields.function(_generate_invalid_message, string='Message', type='char', size=100), |
|
|
'min_type': fields.selection((('static','Fixed value'), ('python','Python Code'), ('local', 'SQL - Local DB'), ('external', 'SQL - Externa DB')), 'Min Type', required=True), |
|
|
|
|
|
|
|
|
'min_type': fields.selection((('static', 'Fixed value'), ('python', 'Python Code'), ('local', 'SQL - Local DB'), ('external', 'SQL - Externa DB')), 'Min Type', required=True), |
|
|
'min_value': fields.function(compute_min_value, string='Minimum', type='float'), |
|
|
'min_value': fields.function(compute_min_value, string='Minimum', type='float'), |
|
|
'min_fixed_value': fields.float('Minimum'), |
|
|
'min_fixed_value': fields.float('Minimum'), |
|
|
'min_code': fields.text('Minimum Computation Code'), |
|
|
'min_code': fields.text('Minimum Computation Code'), |
|
|
'min_dbsource_id': fields.many2one('base.external.dbsource','External DB Source'), |
|
|
|
|
|
'max_type': fields.selection((('static','Fixed value'), ('python','Python Code'), ('local', 'SQL - Local DB'), ('external', 'SQL - External DB')), 'Max Type', required=True), |
|
|
|
|
|
|
|
|
'min_dbsource_id': fields.many2one('base.external.dbsource', 'External DB Source'), |
|
|
|
|
|
'max_type': fields.selection((('static', 'Fixed value'), ('python', 'Python Code'), ('local', 'SQL - Local DB'), ('external', 'SQL - External DB')), 'Max Type', required=True), |
|
|
'max_value': fields.function(compute_max_value, string='Maximum', type='float'), |
|
|
'max_value': fields.function(compute_max_value, string='Maximum', type='float'), |
|
|
'max_fixed_value': fields.float('Maximum'), |
|
|
'max_fixed_value': fields.float('Maximum'), |
|
|
'max_code': fields.text('Maximum Computation Code'), |
|
|
'max_code': fields.text('Maximum Computation Code'), |
|
|
'max_dbsource_id': fields.many2one('base.external.dbsource','External DB Source'), |
|
|
|
|
|
|
|
|
'max_dbsource_id': fields.many2one('base.external.dbsource', 'External DB Source'), |
|
|
'color': fields.char('Color', help='RGB code with #', size=7, required=True), |
|
|
'color': fields.char('Color', help='RGB code with #', size=7, required=True), |
|
|
'threshold_ids': fields.many2many('mgmtsystem.kpi.threshold','mgmtsystem_kpi_threshold_range_rel', 'range_id', 'threshold_id', 'Thresholds'), |
|
|
|
|
|
|
|
|
'threshold_ids': fields.many2many('mgmtsystem.kpi.threshold', 'mgmtsystem_kpi_threshold_range_rel', 'range_id', 'threshold_id', 'Thresholds'), |
|
|
'company_id': fields.many2one('res.company', 'Company') |
|
|
'company_id': fields.many2one('res.company', 'Company') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -157,9 +158,8 @@ class mgmtsystem_kpi_threshold_range(osv.osv): |
|
|
'valid': True, |
|
|
'valid': True, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mgmtsystem_kpi_threshold_range() |
|
|
|
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_threshold(osv.osv): |
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_threshold(orm.Model): |
|
|
""" |
|
|
""" |
|
|
KPI Threshold |
|
|
KPI Threshold |
|
|
""" |
|
|
""" |
|
@ -194,7 +194,7 @@ class mgmtsystem_kpi_threshold(osv.osv): |
|
|
|
|
|
|
|
|
_columns = { |
|
|
_columns = { |
|
|
'name': fields.char('Name', size=50, required=True), |
|
|
'name': fields.char('Name', size=50, required=True), |
|
|
'range_ids': fields.many2many('mgmtsystem.kpi.threshold.range','mgmtsystem_kpi_threshold_range_rel', 'threshold_id', 'range_id', 'Ranges'), |
|
|
|
|
|
|
|
|
'range_ids': fields.many2many('mgmtsystem.kpi.threshold.range', 'mgmtsystem_kpi_threshold_range_rel', 'threshold_id', 'range_id', 'Ranges'), |
|
|
'valid': fields.function(_is_valid_threshold, string='Valid', type='boolean', required=True), |
|
|
'valid': fields.function(_is_valid_threshold, string='Valid', type='boolean', required=True), |
|
|
'invalid_message': fields.function(_generate_invalid_message, string='Message', type='char', size=100), |
|
|
'invalid_message': fields.function(_generate_invalid_message, string='Message', type='char', size=100), |
|
|
'kpi_ids': fields.one2many('mgmtsystem.kpi', 'threshold_id', 'KPIs'), |
|
|
'kpi_ids': fields.one2many('mgmtsystem.kpi', 'threshold_id', 'KPIs'), |
|
@ -231,14 +231,13 @@ class mgmtsystem_kpi_threshold(osv.osv): |
|
|
color = '#FFFFFF' |
|
|
color = '#FFFFFF' |
|
|
for obj in self.browse(cr, uid, ids, context): |
|
|
for obj in self.browse(cr, uid, ids, context): |
|
|
for range_id in obj.range_ids: |
|
|
for range_id in obj.range_ids: |
|
|
range_obj = self.pool.get('mgmtsystem.kpi.threshold.range').browse(cr, uid, range_id.id, context) |
|
|
|
|
|
if range_obj.min_value <= kpi_value <= range_obj.max_value and range_obj.valid: |
|
|
|
|
|
color = range_obj.color |
|
|
|
|
|
|
|
|
range_obj = self.pool.get('mgmtsystem.kpi.threshold.range').browse(cr, uid, range_id.id, context) |
|
|
|
|
|
if range_obj.min_value <= kpi_value <= range_obj.max_value and range_obj.valid: |
|
|
|
|
|
color = range_obj.color |
|
|
return color |
|
|
return color |
|
|
|
|
|
|
|
|
mgmtsystem_kpi_threshold() |
|
|
|
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_history(osv.osv): |
|
|
|
|
|
|
|
|
class mgmtsystem_kpi_history(orm.Model): |
|
|
""" |
|
|
""" |
|
|
History of the KPI |
|
|
History of the KPI |
|
|
""" |
|
|
""" |
|
@ -263,9 +262,8 @@ class mgmtsystem_kpi_history(osv.osv): |
|
|
|
|
|
|
|
|
_order = "date desc" |
|
|
_order = "date desc" |
|
|
|
|
|
|
|
|
mgmtsystem_kpi_threshold() |
|
|
|
|
|
|
|
|
|
|
|
class mgmtsystem_kpi(osv.osv): |
|
|
|
|
|
|
|
|
class mgmtsystem_kpi(orm.Model): |
|
|
""" |
|
|
""" |
|
|
Key Performance Indicators |
|
|
Key Performance Indicators |
|
|
""" |
|
|
""" |
|
@ -305,10 +303,10 @@ class mgmtsystem_kpi(osv.osv): |
|
|
|
|
|
|
|
|
threshold_obj = self.pool.get('mgmtsystem.kpi.threshold').browse(cr, uid, obj.threshold_id.id, context) |
|
|
threshold_obj = self.pool.get('mgmtsystem.kpi.threshold').browse(cr, uid, obj.threshold_id.id, context) |
|
|
values = { |
|
|
values = { |
|
|
'kpi_id': obj.id, |
|
|
|
|
|
|
|
|
'kpi_id': obj.id, |
|
|
'value': kpi_value, |
|
|
'value': kpi_value, |
|
|
'color': threshold_obj.get_color(kpi_value), |
|
|
'color': threshold_obj.get_color(kpi_value), |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
history_obj = self.pool.get('mgmtsystem.kpi.history') |
|
|
history_obj = self.pool.get('mgmtsystem.kpi.history') |
|
|
history_id = history_obj.create(cr, uid, values, context=context) |
|
|
history_id = history_obj.create(cr, uid, values, context=context) |
|
@ -322,13 +320,13 @@ class mgmtsystem_kpi(osv.osv): |
|
|
|
|
|
|
|
|
for obj in self.browse(cr, uid, ids): |
|
|
for obj in self.browse(cr, uid, ids): |
|
|
if obj.periodicity_uom == 'hour': |
|
|
if obj.periodicity_uom == 'hour': |
|
|
new_date = datetime.now() + relativedelta( hours = +obj.periodicity ) |
|
|
|
|
|
|
|
|
new_date = datetime.now()+relativedelta(hours=+obj.periodicity) |
|
|
elif obj.periodicity_uom == 'day': |
|
|
elif obj.periodicity_uom == 'day': |
|
|
new_date = datetime.now() + relativedelta( days = +obj.periodicity ) |
|
|
|
|
|
|
|
|
new_date = datetime.now()+relativedelta(days=+obj.periodicity) |
|
|
elif obj.periodicity_uom == 'week': |
|
|
elif obj.periodicity_uom == 'week': |
|
|
new_date = datetime.now() + relativedelta( weeks = +obj.periodicity ) |
|
|
|
|
|
|
|
|
new_date = datetime.now()+relativedelta(weeks=+obj.periodicity) |
|
|
elif obj.periodicity_uom == 'month': |
|
|
elif obj.periodicity_uom == 'month': |
|
|
new_date = datetime.now() + relativedelta( months = +obj.periodicity ) |
|
|
|
|
|
|
|
|
new_date = datetime.now()+relativedelta(months=+obj.periodicity) |
|
|
|
|
|
|
|
|
values = { |
|
|
values = { |
|
|
'next_execution_date': new_date.strftime('%Y-%m-%d %H:%M:%S'), |
|
|
'next_execution_date': new_date.strftime('%Y-%m-%d %H:%M:%S'), |
|
@ -360,14 +358,14 @@ class mgmtsystem_kpi(osv.osv): |
|
|
_columns = { |
|
|
_columns = { |
|
|
'name': fields.char('Name', size=50, required=True), |
|
|
'name': fields.char('Name', size=50, required=True), |
|
|
'description': fields.text('Description'), |
|
|
'description': fields.text('Description'), |
|
|
'category_id': fields.many2one('mgmtsystem.kpi.category','Category', required=True), |
|
|
|
|
|
'threshold_id': fields.many2one('mgmtsystem.kpi.threshold','Threshold', required=True), |
|
|
|
|
|
|
|
|
'category_id': fields.many2one('mgmtsystem.kpi.category', 'Category', required=True), |
|
|
|
|
|
'threshold_id': fields.many2one('mgmtsystem.kpi.threshold', 'Threshold', required=True), |
|
|
'periodicity': fields.integer('Periodicity'), |
|
|
'periodicity': fields.integer('Periodicity'), |
|
|
'periodicity_uom': fields.selection((('hour','Hour'), ('day','Day'), ('week','Week'), ('month','Month')), 'Periodicity UoM', required=True), |
|
|
|
|
|
|
|
|
'periodicity_uom': fields.selection((('hour', 'Hour'), ('day', 'Day'), ('week', 'Week'), ('month', 'Month')), 'Periodicity UoM', required=True), |
|
|
'next_execution_date': fields.datetime('Next execution date', readonly=True), |
|
|
'next_execution_date': fields.datetime('Next execution date', readonly=True), |
|
|
'value': fields.function(_display_last_kpi_value, string='Value', type='float'), |
|
|
'value': fields.function(_display_last_kpi_value, string='Value', type='float'), |
|
|
'kpi_type': fields.selection((('python','Python'), ('local','SQL - Local DB'), ('external','SQL - External DB')),'KPI Computation Type'), |
|
|
|
|
|
'dbsource_id': fields.many2one('base.external.dbsource','External DB Source'), |
|
|
|
|
|
|
|
|
'kpi_type': fields.selection((('python', 'Python'), ('local', 'SQL - Local DB'), ('external', 'SQL - External DB')), 'KPI Computation Type'), |
|
|
|
|
|
'dbsource_id': fields.many2one('base.external.dbsource', 'External DB Source'), |
|
|
'kpi_code': fields.text('KPI Code', help='SQL code must return the result as \'value\' (i.e. \'SELECT 5 AS value\').'), |
|
|
'kpi_code': fields.text('KPI Code', help='SQL code must return the result as \'value\' (i.e. \'SELECT 5 AS value\').'), |
|
|
'history_ids': fields.one2many('mgmtsystem.kpi.history', 'kpi_id', 'History'), |
|
|
'history_ids': fields.one2many('mgmtsystem.kpi.history', 'kpi_id', 'History'), |
|
|
'active': fields.boolean('Active', help="Only active KPIs will be updated by the scheduler based on the periodicity configuration."), |
|
|
'active': fields.boolean('Active', help="Only active KPIs will be updated by the scheduler based on the periodicity configuration."), |
|
@ -381,6 +379,4 @@ class mgmtsystem_kpi(osv.osv): |
|
|
'periodicity_uom': 'day', |
|
|
'periodicity_uom': 'day', |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mgmtsystem_kpi() |
|
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |