fix
This commit is contained in:
@@ -59,23 +59,23 @@ 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 hasattr(self, 'party_amount') and self.party_amount.paid_amount > 0 and self.party_amount.payment_amount > 0:
|
||||
# self.payment_percentage = (self.party_amount.paid_amount / self.party_amount.payment_amount) * 100
|
||||
# self.party_amount.save()
|
||||
# else:
|
||||
# self.payment_percentage = 100
|
||||
# return super().save(*args, **kwargs)
|
||||
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 hasattr(self, 'party_amount') and self.party_amount.paid_amount > 0 and self.party_amount.payment_amount > 0:
|
||||
self.payment_percentage = (self.party_amount.paid_amount / self.party_amount.payment_amount) * 100
|
||||
self.party_amount.save()
|
||||
else:
|
||||
self.payment_percentage = 100
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Partiya'
|
||||
|
||||
@@ -428,7 +428,10 @@ class PartyExpenceCreateSerializer(serializers.ModelSerializer):
|
||||
if expence.party.currency == "uzs":
|
||||
expence.party.party_amount.payment_amount -= expence.price
|
||||
expence.party.party_amount.paid_amount += expence.price
|
||||
print(expence.party.party_amount.payment_amount)
|
||||
print(expence.party.party_amount.paid_amount)
|
||||
expence.party.save()
|
||||
expence.party.refresh_from_db()
|
||||
elif expence.party.currency == 'usd':
|
||||
expence.party.party_amount.payment_amount -= round(expence.price / usd_value)
|
||||
expence.party.party_amount.paid_amount += round(expence.price / usd_value)
|
||||
|
||||
Reference in New Issue
Block a user