from taxpayers data models import Payer Payment Tax TaxCategory from d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from taxpayers.data.models import Payer, Payment, Tax, TaxCategory
from datetime import date
from django.db.models import Sum
def report_data(period):
if not period:
default = date.today()
period['month'] = default.month
period['year0'] = default.year - 1
period['year1'] = default.year
else:
for key in period.keys():
period[key] = int(period[key])
query = {}
query['year0'] = Payer.objects.filter(payment__date__year=period['year0'], payment__date__month=period['month']).annotate(amount=Sum('payment__amount'))
query['year1'] = Payer.objects.filter(payment__date__year=period['year1'], payment__date__month=period['month']).annotate(amount=Sum('payment__amount'))
#report = [{"id": "1", "name": "пупкин", "amount0":"3", "amount1":"5"},..]
return report