orders: fixed old bugs
This commit is contained in:
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -42,8 +42,8 @@ class Party(BaseModel):
|
|||||||
confirmation = models.CharField(max_length=20, choices=CONFIRMATION, default='EXPECTED')
|
confirmation = models.CharField(max_length=20, choices=CONFIRMATION, default='EXPECTED')
|
||||||
currency = models.CharField(choices=[('usd', 'usd'), ('uzs', 'uzs')], max_length=3, default='uzs')
|
currency = models.CharField(choices=[('usd', 'usd'), ('uzs', 'uzs')], max_length=3, default='uzs')
|
||||||
# percentages
|
# percentages
|
||||||
payment_percentage = models.FloatField(null=True, blank=True)
|
payment_percentage = models.FloatField(default=0.0)
|
||||||
process = models.FloatField(null=True, blank=True)
|
process = models.FloatField(default=0.0)
|
||||||
|
|
||||||
comment = models.TextField(null=True, blank=True)
|
comment = models.TextField(null=True, blank=True)
|
||||||
audit = models.CharField(
|
audit = models.CharField(
|
||||||
@@ -70,10 +70,7 @@ class Party(BaseModel):
|
|||||||
elif self.status == 'PURCHASED':
|
elif self.status == 'PURCHASED':
|
||||||
self.process = 75
|
self.process = 75
|
||||||
elif self.status == 'PARTY_IS_MADE':
|
elif self.status == 'PARTY_IS_MADE':
|
||||||
percentage = 0.0
|
self.process == 100
|
||||||
for order in self.orders.all():
|
|
||||||
percentage += order.completion_percentage
|
|
||||||
self.process = percentage
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -160,10 +160,8 @@ class PartyChangeStatusToIsMadeApiView(generics.GenericAPIView):
|
|||||||
if not serializer.is_valid(raise_exception=True):
|
if not serializer.is_valid(raise_exception=True):
|
||||||
return Response({"success": False, "message": serializer.errors}, status=400)
|
return Response({"success": False, "message": serializer.errors}, status=400)
|
||||||
party = get_object_or_404(Party, id=party_id)
|
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
|
data = serializer.validated_data
|
||||||
|
percentage = 0
|
||||||
for item in data['product']:
|
for item in data['product']:
|
||||||
order_id = item['order_id']
|
order_id = item['order_id']
|
||||||
product_quantity = item['product_quantity']
|
product_quantity = item['product_quantity']
|
||||||
@@ -185,7 +183,13 @@ class PartyChangeStatusToIsMadeApiView(generics.GenericAPIView):
|
|||||||
order.received_count += product_quantity
|
order.received_count += product_quantity
|
||||||
order.received_date = product_receive_date
|
order.received_date = product_receive_date
|
||||||
order.comletion_percentage = completion_percentage
|
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'},
|
{'success': True, 'message': 'party updated'},
|
||||||
status=200
|
status=200
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user