Browse Source

compute average only for kpi type num. Correct utc_midnight

pull/86/head
laetitia.gangloff@acsone.eu 10 years ago
committed by Stéphane Bidoul
parent
commit
18102f8bd5
  1. 14
      mis_builder/models/mis_builder.py
  2. 8
      mis_builder/tests/mis_builder_test.py

14
mis_builder/models/mis_builder.py

@ -53,10 +53,10 @@ def _utc_midnight(d, tz_name, add_day=0):
d = datetime.strptime(d, tools.DEFAULT_SERVER_DATE_FORMAT) d = datetime.strptime(d, tools.DEFAULT_SERVER_DATE_FORMAT)
if add_day: if add_day:
d = d + timedelta(days=add_day) d = d + timedelta(days=add_day)
utc = pytz.timezone('UTC')
utc_tz = pytz.timezone('UTC')
context_tz = pytz.timezone(tz_name) context_tz = pytz.timezone(tz_name)
utc_timestamp = utc.localize(d, is_dst=False)
return datetime.strftime(utc_timestamp.astimezone(context_tz), tools.DEFAULT_SERVER_DATETIME_FORMAT)
local_timestamp = context_tz.localize(d, is_dst=False)
return datetime.strftime(local_timestamp.astimezone(utc_tz), tools.DEFAULT_SERVER_DATETIME_FORMAT)
def _clean(varStr): def _clean(varStr):
@ -167,15 +167,15 @@ class mis_report_kpi(orm.Model):
""" 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'),
sign='+') sign='+')
elif kpi.type == 'num': elif kpi.type == 'num':
if average_value:
value = value / float(average_value)
if average_base_value:
base_value = base_value / float(average_base_value)
if kpi.compare_method == 'diff': if kpi.compare_method == 'diff':
return self._render_num(value - base_value, return self._render_num(value - base_value,
kpi.divider, kpi.dp, kpi.suffix, kpi.divider, kpi.dp, kpi.suffix,

8
mis_builder/tests/mis_builder_test.py

@ -38,13 +38,13 @@ class mis_builder_test(common.TransactionCase):
def test_datetime_conversion(self): def test_datetime_conversion(self):
date_to_convert = '2014-07-05' date_to_convert = '2014-07-05'
date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'Europe/Brussels') date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'Europe/Brussels')
self.assertEqual(date_time_convert, '2014-07-05 02:00:00', 'The converted date time convert must contains hour')
self.assertEqual(date_time_convert, '2014-07-04 22:00:00', 'The converted date time convert must contains hour')
date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'Europe/Brussels', add_day=1) date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'Europe/Brussels', add_day=1)
self.assertEqual(date_time_convert, '2014-07-06 02:00:00', 'The converted date time convert must contains hour')
self.assertEqual(date_time_convert, '2014-07-05 22:00:00', 'The converted date time convert must contains hour')
date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'US/Pacific') date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'US/Pacific')
self.assertEqual(date_time_convert, '2014-07-04 17:00:00', 'The converted date time convert must contains hour')
self.assertEqual(date_time_convert, '2014-07-05 07:00:00', 'The converted date time convert must contains hour')
date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'US/Pacific', add_day=1) date_time_convert = models.mis_builder._utc_midnight(date_to_convert, 'US/Pacific', add_day=1)
self.assertEqual(date_time_convert, '2014-07-05 17:00:00', 'The converted date time convert must contains hour')
self.assertEqual(date_time_convert, '2014-07-06 07:00:00', 'The converted date time convert must contains hour')
def test_fetch_query(self): def test_fetch_query(self):
# create a report on a model without company_id field : account.analytic.balance # create a report on a model without company_id field : account.analytic.balance

Loading…
Cancel
Save