calculate party process and payment_percentag
This commit is contained in:
@@ -59,6 +59,22 @@ class Party(BaseModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'P - {self.number}'
|
return f'P - {self.number}'
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.status in ['NEW', 'CANCELLED', 'DRAFT']:
|
||||||
|
self.process = 0
|
||||||
|
elif self.status == 'EXPECTED':
|
||||||
|
self.process = 25
|
||||||
|
elif self.status == 'PROCESS':
|
||||||
|
self.process = 50
|
||||||
|
elif self.status == 'PURCHASED':
|
||||||
|
self.process = 75
|
||||||
|
elif self.status == 'PARTY_IS_MADE':
|
||||||
|
self.process == 100
|
||||||
|
if self.party_amount and self.party_amount.paid_amount > 0:
|
||||||
|
self.payment_percentage = (self.party_amount.paid_amount / self.party_amount.payment_amount) * 100
|
||||||
|
self.party_amount.save()
|
||||||
|
return super().save(args, kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'Partiya'
|
verbose_name = 'Partiya'
|
||||||
verbose_name_plural = 'Partiyalar'
|
verbose_name_plural = 'Partiyalar'
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class PartyDetailSerializer(serializers.ModelSerializer):
|
|||||||
"payment_date",
|
"payment_date",
|
||||||
"status",
|
"status",
|
||||||
"payment_status",
|
"payment_status",
|
||||||
|
"payment_percentage",
|
||||||
"process",
|
"process",
|
||||||
"confirmation",
|
"confirmation",
|
||||||
"comment",
|
"comment",
|
||||||
@@ -166,6 +167,7 @@ class PartyListSerializer(serializers.ModelSerializer):
|
|||||||
"payment_date",
|
"payment_date",
|
||||||
"status",
|
"status",
|
||||||
"payment_status",
|
"payment_status",
|
||||||
|
"payment_percentage",
|
||||||
"process",
|
"process",
|
||||||
"confirmation",
|
"confirmation",
|
||||||
"comment",
|
"comment",
|
||||||
|
|||||||
Reference in New Issue
Block a user