Skip to content

Commit

Permalink
Merge branch 'release/v0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
RamezIssac committed Nov 26, 2020
2 parents aed9262 + a60cbd2 commit 4db6b69
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 2 additions & 2 deletions slick_reporting/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion slick_reporting/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 4 additions & 4 deletions slick_reporting/form_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions slick_reporting/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion slick_reporting/static/slick_reporting/ra.chartsjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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];
}
Expand Down
16 changes: 7 additions & 9 deletions slick_reporting/templates/slick_reporting/simple_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ <h4 class="py-5">Results</h4>
$('.raReportDateRange').daterangepicker(setDatePickerObj()).on('apply.daterangepicker', function (ev, picker) {

var container = picker.element;
var $startDate = container.find('[name=start_date_0]');
var $startTime = container.find('[name=start_date_1]');
var $endDate = container.find('[name=end_date_0]');
var $endTime = container.find('[name=end_date_1]');
$startDate.val(picker.startDate.format('YYYY') + '-' + picker.startDate.format('MM') + "-" + picker.startDate.format('DD'))
$startTime.val(picker.startDate.format('HH') + ":" + picker.startDate.format('mm'));
$endDate.val(picker.endDate.format('YYYY') + '-' + picker.endDate.format('MM') + "-" + picker.endDate.format('DD'))
$endTime.val(picker.endDate.format('HH') + ":" + picker.endDate.format('mm'));
var $startDate = container.find('[name=start_date]');
var $startTime = container.find('[name=start_date]');
var $endDate = container.find('[name=end_date]');
var $endTime = container.find('[name=end_date]');
$startDate.val(picker.startDate.format('YYYY') + '-' + picker.startDate.format('MM') + "-" + picker.startDate.format('DD') + ' ' +picker.startDate.format('HH') + ":" + picker.startDate.format('mm'))
$endDate.val(picker.endDate.format('YYYY') + '-' + picker.endDate.format('MM') + "-" + picker.endDate.format('DD') +' ' + picker.endDate.format('HH') + ":" + picker.endDate.format('mm'))
container.parents('.panel').find('.refreshReport').trigger('click');

})
Expand All @@ -130,7 +128,7 @@ <h4 class="py-5">Results</h4>
try {
myChart.destroy();
} catch (err) {
console.error(err);
console.info(err);
}
myChart = new Chart($chart, chartObject);

Expand Down
2 changes: 2 additions & 0 deletions slick_reporting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def get_report_generator(self, queryset, for_print):
self.crosstab_compute_reminder = self.form.get_crosstab_compute_reminder()

return self.report_generator_class(self.report_model,
start_date=self.form.cleaned_data['start_date'],
end_date=self.form.cleaned_data['end_date'],
q_filters=q_filters,
kwargs_filters=kw_filters,
date_field=self.date_field,
Expand Down
6 changes: 5 additions & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ class SimpleSales(models.Model):
quantity = models.DecimalField(_('quantity'), max_digits=19, decimal_places=2, default=0)
price = models.DecimalField(_('price'), max_digits=19, decimal_places=2, default=0)
value = models.DecimalField(_('value'), max_digits=19, decimal_places=2, default=0)
created_at = models.DateTimeField(null=True, verbose_name=_('Created at'))


def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
self.value = self.quantity * self.price
self.value = self.quantity * self.price
super().save(force_insert, force_update, using, update_fields)

class Meta:
verbose_name = _('Sale')
verbose_name_plural = _('Sales')
ordering = ['-created_at']


#
# class Invoice(BaseMovementInfo):
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def setUpTestData(cls):

SimpleSales.objects.create(
doc_date=datetime.datetime(year, 1, 2), client=cls.client1,
product=cls.product1, quantity=10, price=10)
product=cls.product1, quantity=10, price=10, created_at=datetime.datetime(year, 1, 5))
SimpleSales.objects.create(
doc_date=datetime.datetime(year, 2, 2), client=cls.client1,
product=cls.product1, quantity=10, price=10)
product=cls.product1, quantity=10, price=10, created_at=datetime.datetime(year, 2, 3))

SimpleSales.objects.create(
doc_date=datetime.datetime(year, 3, 2), client=cls.client1,
product=cls.product1, quantity=10, price=10)
product=cls.product1, quantity=10, price=10, created_at=datetime.datetime(year, 3, 3))

# client 2
SimpleSales.objects.create(
Expand Down

0 comments on commit 4db6b69

Please sign in to comment.