Browse Source

[FIX] fix comparison rendering in presence of AccountingNone

pull/189/head
Stéphane Bidoul 9 years ago
parent
commit
16678d847e
  1. 5
      mis_builder/models/accounting_none.py
  2. 12
      mis_builder/models/mis_builder.py

5
mis_builder/models/accounting_none.py

@ -27,6 +27,8 @@ AccountingNone
-1 -1
>>> 1 - AccountingNone >>> 1 - AccountingNone
1 1
>>> abs(AccountingNone)
AccountingNone
>>> AccountingNone - None >>> AccountingNone - None
AccountingNone AccountingNone
>>> AccountingNone / 2 >>> AccountingNone / 2
@ -115,6 +117,9 @@ class AccountingNoneType(object):
return AccountingNone return AccountingNone
return -other return -other
def __abs__(self):
return self
def __pos__(self): def __pos__(self):
return self return self

12
mis_builder/models/mis_builder.py

@ -158,17 +158,19 @@ class MisReportKpi(models.Model):
average_value, average_base_value): average_value, average_base_value):
""" render the comparison of two KPI values, ready for display """ """ render the comparison of two KPI values, ready for display """
assert len(self) == 1 assert len(self) == 1
if value is None or base_value is None:
return ''
if value is None:
value = AccountingNone
if base_value is None:
base_value = AccountingNone
if self.type == 'pct': if self.type == 'pct':
return self._render_num( return self._render_num(
lang_id, lang_id,
value - base_value, value - base_value,
0.01, self.dp, '', _('pp'), sign='+') 0.01, self.dp, '', _('pp'), sign='+')
elif self.type == 'num': elif self.type == 'num':
if average_value:
if value and average_value:
value = value / float(average_value) value = value / float(average_value)
if average_base_value:
if base_value and average_base_value:
base_value = base_value / float(average_base_value) base_value = base_value / float(average_base_value)
if self.compare_method == 'diff': if self.compare_method == 'diff':
return self._render_num( return self._render_num(
@ -176,7 +178,7 @@ class MisReportKpi(models.Model):
value - base_value, value - base_value,
self.divider, self.dp, self.prefix, self.suffix, sign='+') self.divider, self.dp, self.prefix, self.suffix, sign='+')
elif self.compare_method == 'pct': elif self.compare_method == 'pct':
if round(base_value, self.dp) != 0:
if base_value and round(base_value, self.dp) != 0:
return self._render_num( return self._render_num(
lang_id, lang_id,
(value - base_value) / abs(base_value), (value - base_value) / abs(base_value),

Loading…
Cancel
Save