diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f55a4e..4f8fc74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.4.1] - 2020-11-26 + +- Bring back calculateTotalOnObjectArray (#11) +- Bypassing default ordering by when generating the report (#10) +- Fix in dates in template and view + + ## [0.4.0] - 2020-11-24 [BREAKING] - Renamed `SampleReportView` to `SlickReportView` diff --git a/slick_reporting/__init__.py b/slick_reporting/__init__.py index 1823624..a3b6a97 100644 --- a/slick_reporting/__init__.py +++ b/slick_reporting/__init__.py @@ -1,6 +1,6 @@ default_app_config = 'slick_reporting.apps.ReportAppConfig' -VERSION = (0, 4, 0) +VERSION = (0, 4, 1) -__version__ = '0.4.0' +__version__ = '0.4.1' diff --git a/slick_reporting/fields.py b/slick_reporting/fields.py index d5e5555..8a5b037 100644 --- a/slick_reporting/fields.py +++ b/slick_reporting/fields.py @@ -153,7 +153,7 @@ def prepare(self, q_filters=None, kwargs_filters=None, **kwargs): def get_queryset(self): queryset = self.report_model.objects - return queryset + return queryset.order_by() def get_annotation_name(self): """ diff --git a/slick_reporting/form_factory.py b/slick_reporting/form_factory.py index a6026aa..8a979f8 100644 --- a/slick_reporting/form_factory.py +++ b/slick_reporting/form_factory.py @@ -117,14 +117,14 @@ def report_form_factory(model, fkeys_filter_func=None, foreign_key_widget_func=N fields['start_date'] = forms.DateTimeField(required=False, label=_('From date'), initial=app_settings.SLICK_REPORTING_DEFAULT_START_DATE, - widget=forms.DateTimeInput(format='%m/%d/%Y %H:%M', - attrs={'autocomplete': "off"}), + widget=forms.DateTimeInput( + attrs={'autocomplete': "off"}), ) fields['end_date'] = forms.DateTimeField(required=False, label=_('To date'), initial=app_settings.SLICK_REPORTING_DEFAULT_END_DATE, - widget=forms.DateTimeInput(format='%m/%d/%Y %H:%M', - attrs={'autocomplete': "off"}) + widget=forms.DateTimeInput( + attrs={'autocomplete': "off"}) ) for name, f_field in fkeys_map.items(): diff --git a/slick_reporting/generator.py b/slick_reporting/generator.py index bd55327..3306ba1 100644 --- a/slick_reporting/generator.py +++ b/slick_reporting/generator.py @@ -164,6 +164,7 @@ def __init__(self, report_model=None, main_queryset=None, start_date=None, end_d self.crosstab_compute_reminder = self.crosstab_compute_reminder if crosstab_compute_reminder is None else crosstab_compute_reminder main_queryset = main_queryset or self.report_model.objects + main_queryset = main_queryset.order_by() self.columns = self.columns or columns or [] self.group_by = self.group_by or group_by diff --git a/slick_reporting/static/slick_reporting/ra.chartsjs.js b/slick_reporting/static/slick_reporting/ra.chartsjs.js index 4edf86d..9ae722d 100644 --- a/slick_reporting/static/slick_reporting/ra.chartsjs.js +++ b/slick_reporting/static/slick_reporting/ra.chartsjs.js @@ -66,6 +66,36 @@ return chartObject } + function calculateTotalOnObjectArray(data, columns) { + // Compute totals in array of objects + // example : + // calculateTotalOnObjectArray ([{ value1:500, value2: 70} , {value:200, value2:15} ], ['value']) + // return {'value1': 700, value2:85} + + let total_container = {}; + for (let r = 0; r < data.length; r++) { + + for (let i = 0; i < columns.length; i++) { + if (typeof total_container[columns[i]] == 'undefined') { + total_container[columns[i]] = 0; + } + let val = data[r][columns[i]]; + if (val === '-') val = 0; + + else if (typeof (val) == 'string') { + try { + val = val.replace(/,/g, ''); + } catch (err) { + console.log(err, val, typeof (val)); + } + } + total_container[columns[i]] += parseFloat(val); + } + } + return total_container; +} + + function extractDataFromResponse(response, chartOptions) { let dataFieldName = chartOptions['data_source']; let titleFieldName = chartOptions['title_source']; @@ -157,7 +187,7 @@ function getObjFromArray(objList, obj_key, key_value, failToFirst) { failToFirst = typeof (failToFirst) !== 'undefined'; if (key_value !== '') { - for (var i = 0; i < objList.length; i++) { + for (let i = 0; i < objList.length; i++) { if (objList[i][obj_key] === key_value) { return objList[i]; } diff --git a/slick_reporting/templates/slick_reporting/simple_report.html b/slick_reporting/templates/slick_reporting/simple_report.html index 415ed4e..55fa2cc 100644 --- a/slick_reporting/templates/slick_reporting/simple_report.html +++ b/slick_reporting/templates/slick_reporting/simple_report.html @@ -102,14 +102,12 @@