diff --git a/core/apps/orders/models/party.py b/core/apps/orders/models/party.py index 73f27f9..76af9b3 100644 --- a/core/apps/orders/models/party.py +++ b/core/apps/orders/models/party.py @@ -102,7 +102,10 @@ class PartyAmount(BaseModel): verbose_name = 'Partiya Summasi' verbose_name_plural = 'Partiya summalari' - + def save(self, *args, **kwargs): + if self.calculated_amount < self.paid_amount: + self.payment_amount = self.paid_amount - self.calculated_amount + return super().save(*args, **kwargs) class DeletedParty(BaseModel): party = models.ForeignKey(Party, on_delete=models.CASCADE, related_name='deleted_parties') diff --git a/core/apps/orders/serializers/party.py b/core/apps/orders/serializers/party.py index 7a39eae..3efbb47 100644 --- a/core/apps/orders/serializers/party.py +++ b/core/apps/orders/serializers/party.py @@ -103,6 +103,8 @@ class PartyAmountSerializer(serializers.ModelSerializer): "calculated_amount", "paid_amount", "payment_amount", + "debt_amount", + "total_expense_amount", ] diff --git a/core/apps/orders/views/party.py b/core/apps/orders/views/party.py index 61fb948..7999660 100644 --- a/core/apps/orders/views/party.py +++ b/core/apps/orders/views/party.py @@ -224,7 +224,7 @@ class PartyStatisticsApiView(generics.GenericAPIView): overdue_payments=Sum( 'party_amount__payment_amount', filter=Q(payment_date__lt=today) - ) + ) ) res = { 'usd': usd,