calculate party process and payment_percentag

This commit is contained in:
behruz-dev
2025-10-07 14:17:40 +05:00
parent ceef207b19
commit e66aa6b213
2 changed files with 18 additions and 0 deletions

View File

@@ -59,6 +59,22 @@ class Party(BaseModel):
def __str__(self):
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:
verbose_name = 'Partiya'
verbose_name_plural = 'Partiyalar'