This commit is contained in:
behruz-dev
2025-11-14 15:28:00 +05:00
parent e84937270e
commit 58ba6c3f58
2 changed files with 33 additions and 41 deletions

View File

@@ -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):