This commit is contained in:
behruz-dev
2025-11-18 16:52:03 +05:00
parent 6e0cd06e32
commit 4360177c97

View File

@@ -134,9 +134,25 @@ class CounterpartyBalance(BaseModel):
@property @property
def total_balance(self): def total_balance(self):
usd_course = Decimal(UsdCourse.objects.first().value) if UsdCourse.objects.exists() else Decimal(12000) PartyAmount = apps.get_model('orders', 'PartyAmount')
return self.total_balance_uzs + (self.total_balance_usd * usd_course) Income = apps.get_model('finance', 'Income')
Expense = apps.get_model('finance', 'Expense')
total = Decimal(0)
for item in PartyAmount.objects.filter(party__orders__counterparty=self.counterparty):
rate = item.exchange_rate or Decimal(1)
total += Decimal(item.calculated_amount) * rate
for inc in Income.objects.filter(counterparty=self.counterparty):
rate = inc.exchange_rate or Decimal(1)
total += Decimal(inc.price) * rate
for exp in Expense.objects.filter(counterparty=self.counterparty):
rate = exp.exchange_rate or Decimal(1)
total -= Decimal(exp.price) * rate
return total
def __str__(self): def __str__(self):
return f"{self.counterparty.name}" return f"{self.counterparty.name}"