From edc438bc0ec45b504646d24f869d02d5aed7cb9f Mon Sep 17 00:00:00 2001 From: klmp200 Date: Wed, 5 Apr 2017 14:59:41 +0200 Subject: [PATCH] More readability for sum --- counter/templates/counter/invoices_call.jinja | 2 +- counter/views.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/counter/templates/counter/invoices_call.jinja b/counter/templates/counter/invoices_call.jinja index 626b7060..cac7d7ae 100644 --- a/counter/templates/counter/invoices_call.jinja +++ b/counter/templates/counter/invoices_call.jinja @@ -16,7 +16,7 @@
-

{% trans %}CB Payments{% endtrans %} : {{sum_cb}} €

+

{% trans %}CB Payments{% endtrans %} : {{ sum_cb }} €


diff --git a/counter/views.py b/counter/views.py index e66d5988..06546d23 100644 --- a/counter/views.py +++ b/counter/views.py @@ -1031,10 +1031,10 @@ class InvoiceCallView(CounterAdminTabsMixin, CounterAdminMixin, TemplateView): start_date = start_date.replace(tzinfo=pytz.UTC) end_date = (start_date + timedelta(days=32)).replace(day=1, hour=0, minute=0, microsecond=0) from django.db.models import Sum, Case, When, F, DecimalField - kwargs['sum_cb']= sum([r.amount for r in Refilling.objects.filter(payment_method='CARD', is_validated=True, - date__gte=start_date, date__lte=end_date)]) + sum( - [s.quantity*s.unit_price for s in Selling.objects.filter(payment_method='CARD', is_validated=True, - date__gte=start_date, date__lte=end_date)]) + kwargs['sum_cb'] = sum([r.amount for r in Refilling.objects.filter(payment_method='CARD', is_validated=True, + date__gte=start_date, date__lte=end_date)]) + kwargs['sum_cb'] += sum([s.quantity*s.unit_price for s in Selling.objects.filter(payment_method='CARD', is_validated=True, + date__gte=start_date, date__lte=end_date)]) kwargs['start_date'] = start_date kwargs['sums'] = Selling.objects.values('club__name').annotate(selling_sum=Sum( Case(When(date__gte=start_date,