Browse Source

Fix thresholds invalid calculation

pull/1095/head
Iván Todorovich 7 years ago
parent
commit
b307e3f2c1
  1. 14
      kpi/models/kpi_threshold.py
  2. 6
      kpi/models/kpi_threshold_range.py

14
kpi/models/kpi_threshold.py

@ -13,15 +13,19 @@ class KPIThreshold(models.Model):
@api.multi
def _compute_is_valid_threshold(self):
result = {}
for obj in self:
# check if ranges overlap
# TODO: This code can be done better
obj.valid = True
for range1 in obj.range_ids:
for range2 in obj.range_ids:
if (range1.valid and range2.valid and
range1.min_value < range2.min_value):
obj.valid = range1.max_value <= range2.min_value
if not range1.valid:
obj.valid = False
break
for range2 in (obj.range_ids-range1):
if (range1.max_value >= range2.min_value and
range1.min_value <= range2.max_value):
obj.valid = False
break
if obj.valid:
obj.invalid_message = None
else:

6
kpi/models/kpi_threshold_range.py

@ -95,7 +95,6 @@ class KPIThresholdRange(models.Model):
@api.multi
def _compute_min_value(self):
result = {}
for obj in self:
value = None
error = None
@ -121,11 +120,9 @@ class KPIThresholdRange(models.Model):
error = str(e)
obj.min_value = value
obj.min_error = error
return result
@api.multi
def _compute_max_value(self):
result = {}
for obj in self:
value = None
error = None
@ -151,11 +148,9 @@ class KPIThresholdRange(models.Model):
error = str(e)
obj.max_value = value
obj.max_error = error
return result
@api.multi
def _compute_is_valid_range(self):
result = {}
for obj in self:
if obj.min_error or obj.max_error:
obj.valid = False
@ -170,5 +165,4 @@ class KPIThresholdRange(models.Model):
else:
obj.valid = True
obj.invalid_message = ""
return result
Loading…
Cancel
Save