|
@ -154,33 +154,45 @@ class MisReportKpi(models.Model): |
|
|
|
|
|
|
|
|
def render_comparison(self, lang_id, value, base_value, |
|
|
def render_comparison(self, lang_id, value, base_value, |
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
If the difference is 0, an empty string is returned. |
|
|
|
|
|
""" |
|
|
assert len(self) == 1 |
|
|
assert len(self) == 1 |
|
|
if value is None: |
|
|
if value is None: |
|
|
value = AccountingNone |
|
|
value = AccountingNone |
|
|
if base_value is None: |
|
|
if base_value is None: |
|
|
base_value = AccountingNone |
|
|
base_value = AccountingNone |
|
|
if self.type == 'pct': |
|
|
if self.type == 'pct': |
|
|
return self._render_num( |
|
|
|
|
|
lang_id, |
|
|
|
|
|
value - base_value, |
|
|
|
|
|
0.01, self.dp, '', _('pp'), sign='+') |
|
|
|
|
|
|
|
|
delta = value - base_value |
|
|
|
|
|
if delta and round(delta, self.dp) != 0: |
|
|
|
|
|
return self._render_num( |
|
|
|
|
|
lang_id, |
|
|
|
|
|
delta, |
|
|
|
|
|
0.01, self.dp, '', _('pp'), |
|
|
|
|
|
sign='+') |
|
|
elif self.type == 'num': |
|
|
elif self.type == 'num': |
|
|
if value and average_value: |
|
|
if value and average_value: |
|
|
value = value / float(average_value) |
|
|
value = value / float(average_value) |
|
|
if base_value and 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( |
|
|
|
|
|
lang_id, |
|
|
|
|
|
value - base_value, |
|
|
|
|
|
self.divider, self.dp, self.prefix, self.suffix, sign='+') |
|
|
|
|
|
elif self.compare_method == 'pct': |
|
|
|
|
|
if base_value and round(base_value, self.dp) != 0: |
|
|
|
|
|
|
|
|
delta = value - base_value |
|
|
|
|
|
if delta and round(delta, self.dp) != 0: |
|
|
return self._render_num( |
|
|
return self._render_num( |
|
|
lang_id, |
|
|
lang_id, |
|
|
(value - base_value) / abs(base_value), |
|
|
|
|
|
0.01, self.dp, '', '%', sign='+') |
|
|
|
|
|
|
|
|
delta, |
|
|
|
|
|
self.divider, self.dp, self.prefix, self.suffix, |
|
|
|
|
|
sign='+') |
|
|
|
|
|
elif self.compare_method == 'pct': |
|
|
|
|
|
if base_value and round(base_value, self.dp) != 0: |
|
|
|
|
|
delta = (value - base_value) / abs(base_value) |
|
|
|
|
|
if delta and round(delta, self.dp) != 0: |
|
|
|
|
|
return self._render_num( |
|
|
|
|
|
lang_id, |
|
|
|
|
|
delta, |
|
|
|
|
|
0.01, self.dp, '', '%', |
|
|
|
|
|
sign='+') |
|
|
return '' |
|
|
return '' |
|
|
|
|
|
|
|
|
def _render_num(self, lang_id, value, divider, |
|
|
def _render_num(self, lang_id, value, divider, |
|
|