fix
This commit is contained in:
@@ -7,6 +7,5 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
parties = Party.objects.all()
|
parties = Party.objects.all()
|
||||||
for party in parties:
|
for party in parties:
|
||||||
party.party_amount.payment_amount = party.party_amount.calculated_amount - party.party_amount.paid_amount
|
|
||||||
party.party_amount.save()
|
party.party_amount.save()
|
||||||
self.stdout.write("Parties updated")
|
self.stdout.write("Parties updated")
|
||||||
@@ -94,6 +94,17 @@ class PartyAmount(BaseModel):
|
|||||||
payment_amount = models.BigIntegerField(default=0)
|
payment_amount = models.BigIntegerField(default=0)
|
||||||
debt_amount = models.BigIntegerField(default=0)
|
debt_amount = models.BigIntegerField(default=0)
|
||||||
total_expense_amount = models.BigIntegerField(default=0)
|
total_expense_amount = models.BigIntegerField(default=0)
|
||||||
|
overdue_amount = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.calculated_amount < self.paid_amount:
|
||||||
|
self.overdue_amount = self.paid_amount - self.calculated_amount
|
||||||
|
elif self.calculated_amount > self.paid_amount:
|
||||||
|
self.payment_amount = self.calculated_amount - self.paid_amount
|
||||||
|
else:
|
||||||
|
self.overdue_amount = 0
|
||||||
|
self.payment_amount = 0
|
||||||
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.party} amount'
|
return f'{self.party} amount'
|
||||||
|
|||||||
@@ -94,8 +94,6 @@ class PartyCreateSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
|
|
||||||
class PartyAmountSerializer(serializers.ModelSerializer):
|
class PartyAmountSerializer(serializers.ModelSerializer):
|
||||||
payment_amount = serializers.SerializerMethodField(method_name='get_payment_amount')
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PartyAmount
|
model = PartyAmount
|
||||||
fields = [
|
fields = [
|
||||||
@@ -107,14 +105,9 @@ class PartyAmountSerializer(serializers.ModelSerializer):
|
|||||||
"payment_amount",
|
"payment_amount",
|
||||||
"debt_amount",
|
"debt_amount",
|
||||||
"total_expense_amount",
|
"total_expense_amount",
|
||||||
|
"overdue_amount"
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_payment_amount(self, obj):
|
|
||||||
if obj.calculated_amount < obj.paid_amount:
|
|
||||||
return obj.paid_amount - obj.calculated_amount
|
|
||||||
else:
|
|
||||||
return obj.calculated_amount - obj.paid_amount
|
|
||||||
|
|
||||||
|
|
||||||
class PartyDetailSerializer(serializers.ModelSerializer):
|
class PartyDetailSerializer(serializers.ModelSerializer):
|
||||||
orders = OrderListSerializer(many=True)
|
orders = OrderListSerializer(many=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user