Browse Source

compute average in comparison column

pull/86/head
laetitia.gangloff@acsone.eu 10 years ago
committed by Stéphane Bidoul
parent
commit
1acd8cbc75
  1. 14
      mis_builder/models/mis_builder.py

14
mis_builder/models/mis_builder.py

@ -162,10 +162,14 @@ class mis_report_kpi(orm.Model):
else: else:
return unicode(value) return unicode(value)
def _render_comparison(self, kpi, value, base_value):
def _render_comparison(self, kpi, value, 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 value is None or base_value is None: if value is None or base_value is None:
return '' return ''
if average_value:
value = value / float(average_value)
if average_base_value:
base_value = base_value / float(average_base_value)
if kpi.type == 'pct': if kpi.type == 'pct':
return self._render_num(value - base_value, return self._render_num(value - base_value,
0.01, kpi.dp, _('pp'), 0.01, kpi.dp, _('pp'),
@ -584,7 +588,13 @@ class mis_report_instance(orm.Model):
for kpi in r.report_id.kpi_ids: for kpi in r.report_id.kpi_ids:
content[kpi.name]['cols'].append({'val_r': kpi_obj._render_comparison(kpi, content[kpi.name]['cols'].append({'val_r': kpi_obj._render_comparison(kpi,
column1_values[kpi.name]['val'], column1_values[kpi.name]['val'],
column2_values[kpi.name]['val'])})
column2_values[kpi.name]['val'],
(datetime.strptime(period.date_to, tools.DEFAULT_SERVER_DATE_FORMAT) -
datetime.strptime(period.date_from,
tools.DEFAULT_SERVER_DATE_FORMAT)).days + 1,
(datetime.strptime(compare_col.date_to, tools.DEFAULT_SERVER_DATE_FORMAT) -
datetime.strptime(compare_col.date_from,
tools.DEFAULT_SERVER_DATE_FORMAT)).days + 1)})
return {'header': header, return {'header': header,
'content': content} 'content': content}
Loading…
Cancel
Save