From aa8be776bcc4eb2cbcc1eab93cb489ae1421baec Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Tue, 7 Oct 2025 16:28:28 +0500 Subject: [PATCH] change type --- ..._partyamount_calculated_amount_and_more.py | 28 +++++++++++++++++++ core/apps/orders/models/party.py | 16 +++++------ 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 core/apps/orders/migrations/0027_alter_partyamount_calculated_amount_and_more.py diff --git a/core/apps/orders/migrations/0027_alter_partyamount_calculated_amount_and_more.py b/core/apps/orders/migrations/0027_alter_partyamount_calculated_amount_and_more.py new file mode 100644 index 0000000..ff0127e --- /dev/null +++ b/core/apps/orders/migrations/0027_alter_partyamount_calculated_amount_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.2.4 on 2025-10-07 16:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orders', '0026_alter_order_qqs_alter_order_qqs_price_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='partyamount', + name='calculated_amount', + field=models.BigIntegerField(default=0), + ), + migrations.AlterField( + model_name='partyamount', + name='cost_amount', + field=models.BigIntegerField(default=0), + ), + migrations.AlterField( + model_name='partyamount', + name='paid_amount', + field=models.BigIntegerField(default=0), + ), + ] diff --git a/core/apps/orders/models/party.py b/core/apps/orders/models/party.py index 6376c4e..9e8f4a6 100644 --- a/core/apps/orders/models/party.py +++ b/core/apps/orders/models/party.py @@ -70,11 +70,11 @@ class Party(BaseModel): 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 + 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: @@ -85,9 +85,9 @@ class Party(BaseModel): class PartyAmount(BaseModel): party = models.OneToOneField(Party, on_delete=models.CASCADE, related_name='party_amount') total_price = models.PositiveBigIntegerField() - cost_amount = models.PositiveBigIntegerField(default=0) - calculated_amount = models.PositiveBigIntegerField(default=0) - paid_amount = models.PositiveBigIntegerField(default=0) + cost_amount = models.BigIntegerField(default=0) + calculated_amount = models.BigIntegerField(default=0) + paid_amount = models.BigIntegerField(default=0) payment_amount = models.BigIntegerField(default=0) def __str__(self):