Commit 6ca183ad authored by Sli's avatar Sli

Better sum writing

parent 53a2a160
Pipeline #876 passed with stage
in 3 minutes and 29 seconds
...@@ -1031,14 +1031,10 @@ class InvoiceCallView(CounterAdminTabsMixin, CounterAdminMixin, TemplateView): ...@@ -1031,14 +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
sum_cb = 0 kwargs['sum_cb']= sum([r.amount for r in Refilling.objects.filter(payment_method='CARD', is_validated=True,
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,
sum_cb +=r.amount date__gte=start_date, date__lte=end_date)])
for s in Selling.objects.filter(payment_method='CARD', is_validated=True,
date__gte=start_date, date__lte=end_date):
sum_cb +=s.quantity*s.unit_price
kwargs['sum_cb'] = sum_cb
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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment