fucking counterparty statistics not done yet! fuck
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.db import models
|
||||
from django.apps import apps
|
||||
|
||||
from core.apps.shared.models import BaseModel, Region, District
|
||||
from core.apps.accounts.models import User
|
||||
from core.apps.accounts.models import User
|
||||
|
||||
|
||||
class CounterpartyFolder(BaseModel):
|
||||
@@ -99,18 +100,61 @@ class CounterpartyBalance(BaseModel):
|
||||
|
||||
@property
|
||||
def total_balance_usd(self):
|
||||
Party = apps.get_model('orders', 'Party')
|
||||
|
||||
debit = Decimal(self.debit_usd or 0)
|
||||
kredit = Decimal(self.kredit_usd or 0)
|
||||
return debit - kredit
|
||||
|
||||
party_payment = Party.objects.filter(
|
||||
orders__counterparty=self.counterparty,
|
||||
is_deleted=False,
|
||||
currency='usd'
|
||||
).aggregate(
|
||||
payment_amount=models.Sum('party_amount__payment_amount')
|
||||
)['payment_amount'] or 0
|
||||
|
||||
party_overdue = Party.objects.filter(
|
||||
orders__counterparty=self.counterparty,
|
||||
is_deleted=False,
|
||||
currency='usd'
|
||||
).aggregate(
|
||||
overdue_amount=models.Sum('party_amount__overdue_amount')
|
||||
)['overdue_amount'] or 0
|
||||
|
||||
party_amount = Decimal(party_payment or 0) - Decimal(party_overdue or 0)
|
||||
|
||||
return debit - kredit + party_amount
|
||||
|
||||
|
||||
@property
|
||||
def total_balance_uzs(self):
|
||||
Party = apps.get_model('orders', 'Party')
|
||||
|
||||
debit = Decimal(self.debit_uzs or 0)
|
||||
kredit = Decimal(self.kredit_uzs or 0)
|
||||
return debit - kredit
|
||||
|
||||
|
||||
party_payment = Party.objects.filter(
|
||||
orders__counterparty=self.counterparty,
|
||||
is_deleted=False,
|
||||
currency='uzs'
|
||||
).aggregate(
|
||||
payment_amount=models.Sum('party_amount__payment_amount')
|
||||
)['payment_amount'] or 0
|
||||
|
||||
party_overdue = Party.objects.filter(
|
||||
orders__counterparty=self.counterparty,
|
||||
is_deleted=False,
|
||||
currency='uzs'
|
||||
).aggregate(
|
||||
overdue_amount=models.Sum('party_amount__overdue_amount')
|
||||
)['overdue_amount'] or 0
|
||||
|
||||
party_amount = Decimal(party_payment or 0) - Decimal(party_overdue or 0)
|
||||
|
||||
return debit - kredit + party_amount
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.counterparty.name} | USD: {self.total_balance_usd} | UZS: {self.total_balance_uzs}"
|
||||
return f"{self.counterparty.name}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Kontragent Balansi"
|
||||
|
||||
Reference in New Issue
Block a user