More readability for sum

This commit is contained in:
Antoine Bartuccio 2017-04-05 14:59:41 +02:00
parent 6ca183ad55
commit edc438bc0e
2 changed files with 5 additions and 5 deletions

View File

@ -16,7 +16,7 @@
<input type="submit" value="{% trans %}Go{% endtrans %}" /> <input type="submit" value="{% trans %}Go{% endtrans %}" />
</form> </form>
<br> <br>
<p>{% trans %}CB Payments{% endtrans %} : {{sum_cb}} €</p> <p>{% trans %}CB Payments{% endtrans %} : {{ sum_cb }} €</p>
<br> <br>
<table> <table>
<thead> <thead>

View File

@ -1031,10 +1031,10 @@ class InvoiceCallView(CounterAdminTabsMixin, CounterAdminMixin, TemplateView):
start_date = start_date.replace(tzinfo=pytz.UTC) start_date = start_date.replace(tzinfo=pytz.UTC)
end_date = (start_date + timedelta(days=32)).replace(day=1, hour=0, minute=0, microsecond=0) 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 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, 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( date__gte=start_date, date__lte=end_date)])
[s.quantity*s.unit_price for s in Selling.objects.filter(payment_method='CARD', is_validated=True, 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)]) date__gte=start_date, date__lte=end_date)])
kwargs['start_date'] = start_date kwargs['start_date'] = start_date
kwargs['sums'] = Selling.objects.values('club__name').annotate(selling_sum=Sum( kwargs['sums'] = Selling.objects.values('club__name').annotate(selling_sum=Sum(
Case(When(date__gte=start_date, Case(When(date__gte=start_date,