fix
This commit is contained in:
@@ -192,20 +192,17 @@ class CounterPartyIncomeExpenceStatisticsApiView(views.APIView):
|
||||
counterparty=counterparty,
|
||||
is_deleted=False,
|
||||
)
|
||||
income_by_currency = {}
|
||||
expence_by_currency = {}
|
||||
|
||||
|
||||
income_by_currency = {
|
||||
'uzs': {'total': 0, 'count': 0, 'amount_uzs': 0},
|
||||
'usd': {'total': 0, 'count': 0, 'amount_uzs': 0}
|
||||
}
|
||||
|
||||
for income in incomes:
|
||||
currency = income.currency
|
||||
amount = income.price
|
||||
|
||||
if currency not in income_by_currency:
|
||||
income_by_currency[currency] = {
|
||||
'total': 0,
|
||||
'count': 0,
|
||||
'amount_uzs': 0
|
||||
}
|
||||
|
||||
income_by_currency[currency]['total'] += amount
|
||||
income_by_currency[currency]['count'] += 1
|
||||
|
||||
@@ -214,17 +211,15 @@ class CounterPartyIncomeExpenceStatisticsApiView(views.APIView):
|
||||
else:
|
||||
income_by_currency[currency]['amount_uzs'] += amount
|
||||
|
||||
expence_by_currency = {
|
||||
'uzs': {'total': 0, 'count': 0, 'amount_uzs': 0},
|
||||
'usd': {'total': 0, 'count': 0, 'amount_uzs': 0}
|
||||
}
|
||||
|
||||
for expence in expences:
|
||||
currency = expence.currency
|
||||
amount = expence.price
|
||||
|
||||
if currency not in expence_by_currency:
|
||||
expence_by_currency[currency] = {
|
||||
'total': 0,
|
||||
'count': 0,
|
||||
'amount_uzs': 0
|
||||
}
|
||||
|
||||
expence_by_currency[currency]['total'] += amount
|
||||
expence_by_currency[currency]['count'] += 1
|
||||
|
||||
@@ -233,12 +228,10 @@ class CounterPartyIncomeExpenceStatisticsApiView(views.APIView):
|
||||
else:
|
||||
expence_by_currency[currency]['amount_uzs'] += amount
|
||||
|
||||
# UZS bo'yicha jami
|
||||
total_income_uzs = sum(data['amount_uzs'] for data in income_by_currency.values())
|
||||
total_expence_uzs = sum(data['amount_uzs'] for data in expence_by_currency.values())
|
||||
balance_uzs = total_income_uzs - total_expence_uzs
|
||||
|
||||
# USD bo'yicha jami
|
||||
total_income_usd = income_by_currency.get('usd', {}).get('total', 0)
|
||||
total_expence_usd = expence_by_currency.get('usd', {}).get('total', 0)
|
||||
balance_usd = total_income_usd - total_expence_usd
|
||||
|
||||
Reference in New Issue
Block a user