orders: fixed old bugs

This commit is contained in:
behruz-dev
2025-11-11 16:56:35 +05:00
parent fe1542b540
commit 4aea353b75
3 changed files with 34 additions and 10 deletions

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.4 on 2025-11-11 16:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('orders', '0037_deletedparty_user'),
]
operations = [
migrations.AlterField(
model_name='party',
name='payment_percentage',
field=models.FloatField(default=0.0),
),
migrations.AlterField(
model_name='party',
name='process',
field=models.FloatField(default=0.0),
),
]

View File

@@ -42,8 +42,8 @@ class Party(BaseModel):
confirmation = models.CharField(max_length=20, choices=CONFIRMATION, default='EXPECTED')
currency = models.CharField(choices=[('usd', 'usd'), ('uzs', 'uzs')], max_length=3, default='uzs')
# percentages
payment_percentage = models.FloatField(null=True, blank=True)
process = models.FloatField(null=True, blank=True)
payment_percentage = models.FloatField(default=0.0)
process = models.FloatField(default=0.0)
comment = models.TextField(null=True, blank=True)
audit = models.CharField(
@@ -70,10 +70,7 @@ class Party(BaseModel):
elif self.status == 'PURCHASED':
self.process = 75
elif self.status == 'PARTY_IS_MADE':
percentage = 0.0
for order in self.orders.all():
percentage += order.completion_percentage
self.process = percentage
self.process == 100
return super().save(*args, **kwargs)
class Meta:

View File

@@ -160,10 +160,8 @@ class PartyChangeStatusToIsMadeApiView(generics.GenericAPIView):
if not serializer.is_valid(raise_exception=True):
return Response({"success": False, "message": serializer.errors}, status=400)
party = get_object_or_404(Party, id=party_id)
party.status = 'PARTY_IS_MADE'
party.closed_date = now().date()
party.save()
data = serializer.validated_data
percentage = 0
for item in data['product']:
order_id = item['order_id']
product_quantity = item['product_quantity']
@@ -185,7 +183,13 @@ class PartyChangeStatusToIsMadeApiView(generics.GenericAPIView):
order.received_count += product_quantity
order.received_date = product_receive_date
order.comletion_percentage = completion_percentage
return Response(
percentage += completion_percentage
if percentage == 100:
party.status = 'PARTY_IS_MADE'
party.process = percentage
party.closed_date = now().date()
party.save()
return Response(
{'success': True, 'message': 'party updated'},
status=200
)