From 18102f8bd578d6bbc166c8cddab29d85ce14aee9 Mon Sep 17 00:00:00 2001 From: "laetitia.gangloff@acsone.eu" Date: Thu, 31 Jul 2014 19:05:18 +0200 Subject: [PATCH] compute average only for kpi type num. Correct utc_midnight --- mis_builder/models/mis_builder.py | 14 +++++++------- mis_builder/tests/mis_builder_test.py | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 35e3ac9f..c6a6c75a 100644 --- a/mis_builder/models/mis_builder.py +++ b/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) if add_day: d = d + timedelta(days=add_day) - utc = pytz.timezone('UTC') + utc_tz = pytz.timezone('UTC') 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): @@ -167,15 +167,15 @@ class mis_report_kpi(orm.Model): """ render the comparison of two KPI values, ready for display """ if value is None or base_value is None: 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': return self._render_num(value - base_value, 0.01, kpi.dp, _('pp'), sign='+') 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': return self._render_num(value - base_value, kpi.divider, kpi.dp, kpi.suffix, diff --git a/mis_builder/tests/mis_builder_test.py b/mis_builder/tests/mis_builder_test.py index e59c7433..e067cc93 100644 --- a/mis_builder/tests/mis_builder_test.py +++ b/mis_builder/tests/mis_builder_test.py @@ -38,13 +38,13 @@ class mis_builder_test(common.TransactionCase): def test_datetime_conversion(self): date_to_convert = '2014-07-05' 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) - 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') - 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) - 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): # create a report on a model without company_id field : account.analytic.balance