fix
This commit is contained in:
@@ -134,9 +134,25 @@ class CounterpartyBalance(BaseModel):
|
||||
|
||||
@property
|
||||
def total_balance(self):
|
||||
usd_course = Decimal(UsdCourse.objects.first().value) if UsdCourse.objects.exists() else Decimal(12000)
|
||||
return self.total_balance_uzs + (self.total_balance_usd * usd_course)
|
||||
PartyAmount = apps.get_model('orders', 'PartyAmount')
|
||||
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):
|
||||
return f"{self.counterparty.name}"
|
||||
|
||||
Reference in New Issue
Block a user