Browse Source

Increase version

pull/267/head
Iván Todorovich 7 years ago
committed by Adrià Gil Sorribes
parent
commit
46ebc0ee5b
  1. 2
      kpi/__openerp__.py
  2. 43
      kpi/models/kpi_threshold_range.py
  3. 9
      kpi/views/kpi_threshold_range.xml

2
kpi/__openerp__.py

@ -4,7 +4,7 @@
{ {
"name": "Key Performance Indicator", "name": "Key Performance Indicator",
"version": "9.0.1.0.0",
"version": "9.0.2.0.0",
"author": "Savoir-faire Linux,Odoo Community Association (OCA)", "author": "Savoir-faire Linux,Odoo Community Association (OCA)",
"website": "http://www.savoirfairelinux.com", "website": "http://www.savoirfairelinux.com",
"license": "AGPL-3", "license": "AGPL-3",

43
kpi/models/kpi_threshold_range.py

@ -46,7 +46,7 @@ class KPIThresholdRange(models.Model):
valid = fields.Boolean(string='Valid', required=True, valid = fields.Boolean(string='Valid', required=True,
compute="_compute_is_valid_range", default=True) compute="_compute_is_valid_range", default=True)
invalid_message = fields.Char(string='Message', size=100, invalid_message = fields.Char(string='Message', size=100,
compute="_compute_generate_invalid_message")
compute="_compute_is_valid_range")
min_type = fields.Selection(( min_type = fields.Selection((
('static', 'Fixed value'), ('static', 'Fixed value'),
('python', 'Python Code'), ('python', 'Python Code'),
@ -56,6 +56,7 @@ class KPIThresholdRange(models.Model):
min_value = fields.Float(string='Minimum', compute="_compute_min_value") min_value = fields.Float(string='Minimum', compute="_compute_min_value")
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_error = fields.Char('Error', compute="_compute_min_value")
min_dbsource_id = fields.Many2one( min_dbsource_id = fields.Many2one(
'base.external.dbsource', 'base.external.dbsource',
'External DB Source', 'External DB Source',
@ -69,6 +70,7 @@ class KPIThresholdRange(models.Model):
max_value = fields.Float(string='Maximum', compute="_compute_max_value") max_value = fields.Float(string='Maximum', compute="_compute_max_value")
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_error = fields.Char('Error', compute="_compute_max_value")
max_dbsource_id = fields.Many2one( max_dbsource_id = fields.Many2one(
'base.external.dbsource', 'base.external.dbsource',
'External DB Source', 'External DB Source',
@ -90,11 +92,14 @@ class KPIThresholdRange(models.Model):
'res.company', 'Company', 'res.company', 'Company',
default=lambda self: self.env.user.company_id.id) default=lambda self: self.env.user.company_id.id)
@api.multi @api.multi
def _compute_min_value(self): def _compute_min_value(self):
result = {} result = {}
for obj in self: for obj in self:
value = None value = None
error = None
try:
if obj.min_type == 'local' and is_sql_or_ddl_statement( if obj.min_type == 'local' and is_sql_or_ddl_statement(
obj.min_code): obj.min_code):
self.env.cr.execute(obj.min_code) self.env.cr.execute(obj.min_code)
@ -111,7 +116,11 @@ class KPIThresholdRange(models.Model):
value = safe_eval(obj.min_code) value = safe_eval(obj.min_code)
else: else:
value = obj.min_fixed_value value = obj.min_fixed_value
except Exception as e:
value = None
error = str(e)
obj.min_value = value obj.min_value = value
obj.min_error = error
return result return result
@api.multi @api.multi
@ -119,43 +128,47 @@ class KPIThresholdRange(models.Model):
result = {} result = {}
for obj in self: for obj in self:
value = None value = None
error = None
try:
if obj.max_type == 'local' and is_sql_or_ddl_statement( if obj.max_type == 'local' and is_sql_or_ddl_statement(
obj.max_code): obj.max_code):
self.env.cr.execute(obj.max_code) self.env.cr.execute(obj.max_code)
dic = self.env.cr.dictfetchall() dic = self.env.cr.dictfetchall()
if is_one_value(dic): if is_one_value(dic):
value = dic[0]['value'] value = dic[0]['value']
elif obj.max_type == 'python':
value = safe_eval(obj.max_code)
elif (obj.max_type == 'external' and obj.max_dbsource_id.id and elif (obj.max_type == 'external' and obj.max_dbsource_id.id and
is_sql_or_ddl_statement(obj.max_code)): is_sql_or_ddl_statement(obj.max_code)):
dbsrc_obj = obj.max_dbsource_id dbsrc_obj = obj.max_dbsource_id
res = dbsrc_obj.execute(obj.max_code) res = dbsrc_obj.execute(obj.max_code)
if is_one_value(res): if is_one_value(res):
value = res[0]['value'] value = res[0]['value']
elif obj.max_type == 'python':
value = safe_eval(obj.max_code)
else: else:
value = obj.max_fixed_value value = obj.max_fixed_value
except Exception as e:
value = None
error = str(e)
obj.max_value = value obj.max_value = value
obj.max_error = error
return result return result
@api.multi @api.multi
def _compute_is_valid_range(self): def _compute_is_valid_range(self):
result = {} result = {}
for obj in self: for obj in self:
if obj.max_value < obj.min_value:
if obj.min_error or obj.max_error:
obj.valid = False
obj.invalid_message = (
"Either minimum or maximum value has "
"computation errors. Please fix them.")
elif obj.max_value < obj.min_value:
obj.valid = False obj.valid = False
else:
obj.valid = True
return result
@api.multi
def _compute_generate_invalid_message(self):
result = {}
for obj in self:
if obj.valid:
obj.invalid_message = ""
else:
obj.invalid_message = ( obj.invalid_message = (
"Minimum value is greater than the maximum " "Minimum value is greater than the maximum "
"value! Please adjust them.") "value! Please adjust them.")
else:
obj.valid = True
obj.invalid_message = ""
return result return result

9
kpi/views/kpi_threshold_range.xml

@ -37,7 +37,9 @@
<field name="min_fixed_value" colspan="2" attrs="{'invisible' : [('min_type', '!=', 'static')]}"/> <field name="min_fixed_value" colspan="2" attrs="{'invisible' : [('min_type', '!=', 'static')]}"/>
<field name="min_dbsource_id" colspan="2" attrs="{'invisible' : [('min_type', '!=', 'external')]}"/> <field name="min_dbsource_id" colspan="2" attrs="{'invisible' : [('min_type', '!=', 'external')]}"/>
<newline/> <newline/>
<field name="min_code" colspan="4" attrs="{'invisible' : [('min_type', 'NOT IN', ('local','external','python'))]}"/>
<field name="min_code" colspan="6" attrs="{'invisible' : [('min_type', 'NOT IN', ('local','external','python'))]}"/>
<newline/>
<field name="min_error" colspan="6" attrs="{'invisible': [('min_error', '=', False)]}" />
<newline/> <newline/>
<separator string="Maximum" colspan="4"/> <separator string="Maximum" colspan="4"/>
<newline/> <newline/>
@ -45,10 +47,13 @@
<field name="max_fixed_value" attrs="{'invisible' : [('max_type', '!=', 'static')]}"/> <field name="max_fixed_value" attrs="{'invisible' : [('max_type', '!=', 'static')]}"/>
<field name="max_dbsource_id" attrs="{'invisible' : [('max_type', '!=', 'external')]}"/> <field name="max_dbsource_id" attrs="{'invisible' : [('max_type', '!=', 'external')]}"/>
<newline/> <newline/>
<field name="max_code" colspan="4" attrs="{'invisible' : [('max_type', 'NOT IN', ('local','external','python'))]}"/>
<field name="max_code" colspan="6" attrs="{'invisible' : [('max_type', 'NOT IN', ('local','external','python'))]}"/>
<newline/>
<field name="max_error" colspan="6" attrs="{'invisible': [('max_error', '=', False)]}" />
<newline/> <newline/>
<separator string="Thresholds" colspan="4"/> <separator string="Thresholds" colspan="4"/>
<field name="threshold_ids" nolabel="1" colspan="4"/> <field name="threshold_ids" nolabel="1" colspan="4"/>
<separator string="Errors" attrs="{'invisible' : [('invalid_message', '=', '')]}" colspan="4"/>
<field name="invalid_message" nolabel="1" attrs="{'invisible' : [('invalid_message', '=', '')]}" colspan="4"/> <field name="invalid_message" nolabel="1" attrs="{'invisible' : [('invalid_message', '=', '')]}" colspan="4"/>
</group> </group>
</form> </form>

Loading…
Cancel
Save