fix
This commit is contained in:
@@ -346,41 +346,40 @@ class CounterpartyAKTApiView(views.APIView):
|
||||
|
||||
return Response(response, status=200)
|
||||
|
||||
def _group_by_date(self, parties, incomes, expences):
|
||||
def _group_by_date(self, parties, expences, incomes):
|
||||
"""Kun boyicha guruhlash"""
|
||||
daily_data = defaultdict(lambda: {
|
||||
'parties': [],
|
||||
'incomes': [],
|
||||
'expences': [],
|
||||
'incomes': [],
|
||||
'parties_total': Decimal('0'),
|
||||
'day_kredit': Decimal('0'),
|
||||
'day_debit': Decimal('0'),
|
||||
'day_balance': Decimal('0'),
|
||||
'balance_type': 'kredit',
|
||||
'balance_type': 'kredit'
|
||||
})
|
||||
|
||||
# TODO: partiyalarni kun boyicha ajratish
|
||||
for party in parties:
|
||||
date_key = party.closed_date.strftime('%Y-%m-%d')
|
||||
daily_data[date_key]['parties'].append(parties)
|
||||
|
||||
# TODO: kirimlarni kun boyicha ajratish
|
||||
date_key = party.close_date.strftime('%Y-%m-%d')
|
||||
daily_data[date_key]['parties'].append(party)
|
||||
|
||||
party_total = getattr(party, 'total_price', 0) or 0
|
||||
daily_data[date_key]['parties_total'] = daily_data[date_key].get('parties_total', Decimal('0')) + Decimal(party_total)
|
||||
|
||||
for income in incomes:
|
||||
date_key = income.created_at.strftime('%Y-%m-%d')
|
||||
daily_data[date_key]['incomes'].append(parties)
|
||||
|
||||
# TODO: chiqimlarni kun boyicha ajratish
|
||||
daily_data[date_key]['incomes'].append(income)
|
||||
|
||||
for expence in expences:
|
||||
date_key = expence.created_at.strftime('%Y-%m-%d')
|
||||
daily_data[date_key]['expences'].append(parties)
|
||||
|
||||
daily_data[date_key]['expences'].append(expence)
|
||||
|
||||
for date_key in sorted(daily_data.keys(), reverse=True):
|
||||
parties_list = daily_data[date_key]['parties']
|
||||
incomes_list = daily_data[date_key]['incomes']
|
||||
expences_list = daily_data[date_key]['expences']
|
||||
|
||||
parties_total = sum(
|
||||
Decimal(p.party_amount.total_price or 0)
|
||||
for p in parties_list
|
||||
)
|
||||
parties_total = daily_data[date_key].get('parties_total', Decimal('0'))
|
||||
incomes_total = sum(
|
||||
Decimal(i.price or 0)
|
||||
for i in incomes_list
|
||||
@@ -410,4 +409,4 @@ class CounterpartyAKTApiView(views.APIView):
|
||||
'debit': data['day_debit'],
|
||||
}
|
||||
for date, data in daily_data.items()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user