fix
This commit is contained in:
@@ -69,19 +69,19 @@ class CounterpartyBalance(BaseModel):
|
||||
debit_uzs = models.DecimalField(max_digits=15, decimal_places=2, default=0.00)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.balance_usd > 0:
|
||||
self.debit_usd = self.balance_usd
|
||||
self.kredit_usd = Decimal('0.00')
|
||||
elif self.balance_usd < 0:
|
||||
self.kredit_usd = abs(self.balance_usd)
|
||||
self.debit_usd = Decimal('0.00')
|
||||
# if self.balance_usd > 0:
|
||||
# self.debit_usd = self.balance_usd
|
||||
# self.kredit_usd = Decimal('0.00')
|
||||
# elif self.balance_usd < 0:
|
||||
# self.kredit_usd = abs(self.balance_usd)
|
||||
# self.debit_usd = Decimal('0.00')
|
||||
|
||||
if self.balance_uzs > 0:
|
||||
self.debit_uzs = self.balance_uzs
|
||||
self.kredit_uzs = Decimal('0.00')
|
||||
elif self.balance_uzs < 0:
|
||||
self.kredit_uzs = abs(self.balance_uzs)
|
||||
self.debit_uzs = Decimal('0.00')
|
||||
# if self.balance_uzs > 0:
|
||||
# self.debit_uzs = self.balance_uzs
|
||||
# self.kredit_uzs = Decimal('0.00')
|
||||
# elif self.balance_uzs < 0:
|
||||
# self.kredit_uzs = abs(self.balance_uzs)
|
||||
# self.debit_uzs = Decimal('0.00')
|
||||
|
||||
if self.total_balance_usd >= 0:
|
||||
self.kredit_usd = self.total_balance_usd
|
||||
@@ -117,7 +117,6 @@ class CounterpartyBalance(BaseModel):
|
||||
is_deleted=False,
|
||||
currency='usd'
|
||||
).distinct()
|
||||
paid_amount = parties.aggregate(total_price=models.Sum('party_amount__paid_amount'))['total_price'] or 0
|
||||
total_amount = parties.aggregate(total_price=models.Sum('party_amount__calculated_amount'))['total_price'] or 0
|
||||
income = Income.objects.filter(currency='usd', counterparty=self.counterparty).aggregate(
|
||||
total_price=models.Sum("price")
|
||||
@@ -125,11 +124,7 @@ class CounterpartyBalance(BaseModel):
|
||||
expence = Expence.objects.filter(currency='usd', counterparty=self.counterparty).aggregate(
|
||||
total_price=models.Sum("price")
|
||||
)['total_price'] or 0
|
||||
party_amount = total_amount - paid_amount
|
||||
if expence != paid_amount:
|
||||
return (party_amount + income) - expence
|
||||
else:
|
||||
return (total_amount + income) - expence
|
||||
return (total_amount + income) - expence
|
||||
|
||||
@property
|
||||
def total_balance_uzs(self):
|
||||
@@ -142,18 +137,16 @@ class CounterpartyBalance(BaseModel):
|
||||
is_deleted=False,
|
||||
currency='uzs'
|
||||
).distinct()
|
||||
paid_amount = parties.aggregate(total_price=models.Sum('party_amount__paid_amount'))['total_price'] or 0
|
||||
total_amount = parties.aggregate(total_price=models.Sum('party_amount__calculated_amount'))['total_price'] or 0
|
||||
print(total_amount)
|
||||
income = Income.objects.filter(currency='uzs', counterparty=self.counterparty).aggregate(
|
||||
total_price=models.Sum("price")
|
||||
)['total_price'] or 0
|
||||
print(income)
|
||||
expence = Expence.objects.filter(currency='uzs', counterparty=self.counterparty).aggregate(
|
||||
total_price=models.Sum("price")
|
||||
)['total_price'] or 0
|
||||
party_amount = total_amount - paid_amount
|
||||
# if expence != paid_amount:
|
||||
# return (party_amount + income) - expence
|
||||
# else:
|
||||
print(expence)
|
||||
return (total_amount + income) - expence
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -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)
|
||||
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)
|
||||
|
||||
# TODO: kirimlarni kun boyicha ajratish
|
||||
for income in incomes:
|
||||
date_key = income.created_at.strftime('%Y-%m-%d')
|
||||
daily_data[date_key]['incomes'].append(parties)
|
||||
daily_data[date_key]['incomes'].append(income)
|
||||
|
||||
# TODO: chiqimlarni kun boyicha ajratish
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user