feat(orders): store logistics ETA internally in Order and SellerOrder database
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 29s
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 29s
This commit is contained in:
parent
f96ed1e5a3
commit
d32c653013
4 changed files with 34 additions and 1 deletions
18
orders/migrations/0005_order_expected_delivery_date.py
Normal file
18
orders/migrations/0005_order_expected_delivery_date.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 6.1 on 2026-10-14 16:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('orders', '0004_order_awb_number_order_shipping_carrier_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='order',
|
||||||
|
name='expected_delivery_date',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -108,6 +108,7 @@ class Order(models.Model):
|
||||||
awb_number = models.CharField(max_length=100, blank=True, null=True)
|
awb_number = models.CharField(max_length=100, blank=True, null=True)
|
||||||
shipping_carrier = models.CharField(max_length=50, default='Shadowfax')
|
shipping_carrier = models.CharField(max_length=50, default='Shadowfax')
|
||||||
shipping_status = models.CharField(max_length=100, blank=True, null=True, default='new')
|
shipping_status = models.CharField(max_length=100, blank=True, null=True, default='new')
|
||||||
|
expected_delivery_date = models.CharField(max_length=100, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Order {self.id} by {self.user.username}"
|
return f"Order {self.id} by {self.user.username}"
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class OrderSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Order
|
model = Order
|
||||||
fields = ['id', 'username', 'razorpay_order_id', 'razorpay_payment_id', 'total_amount', 'status', 'shipping_address', 'cancellation_reason', 'return_reason', 'placed_at', 'awb_number', 'shipping_carrier', 'shipping_status']
|
fields = ['id', 'username', 'razorpay_order_id', 'razorpay_payment_id', 'total_amount', 'status', 'shipping_address', 'cancellation_reason', 'return_reason', 'placed_at', 'awb_number', 'shipping_carrier', 'shipping_status', 'expected_delivery_date']
|
||||||
|
|
||||||
class AddressSerializer(serializers.ModelSerializer):
|
class AddressSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
||||||
|
|
@ -979,6 +979,20 @@ class OrderTrackView(APIView):
|
||||||
if seller_order and seller_order.status in ['Pending Acceptance', 'Ready to Ship']:
|
if seller_order and seller_order.status in ['Pending Acceptance', 'Ready to Ship']:
|
||||||
SellerOrder.objects.filter(Q(order_id__startswith=f"{order.id}-") | Q(order_id=str(order.id))).update(status='Shipped')
|
SellerOrder.objects.filter(Q(order_id__startswith=f"{order.id}-") | Q(order_id=str(order.id))).update(status='Shipped')
|
||||||
|
|
||||||
|
# Store live ETA in DB internally across Order and SellerOrder
|
||||||
|
live_eta = None
|
||||||
|
if live_data and isinstance(live_data.get('data'), dict):
|
||||||
|
live_eta = live_data['data'].get('expected_delivery_date') or (live_data['data'].get('order_details') or {}).get('expected_delivery_date')
|
||||||
|
|
||||||
|
if order and live_eta and order.expected_delivery_date != str(live_eta):
|
||||||
|
order.expected_delivery_date = str(live_eta)
|
||||||
|
order.save(update_fields=['expected_delivery_date'])
|
||||||
|
|
||||||
|
if live_eta and (order or order_id):
|
||||||
|
SellerOrder.objects.filter(
|
||||||
|
Q(order_id__startswith=f"{order.id}-") | Q(order_id=str(order.id)) if order else Q(order_id=str(order_id))
|
||||||
|
).update(eta=str(live_eta))
|
||||||
|
|
||||||
if not live_data or 'data' not in live_data:
|
if not live_data or 'data' not in live_data:
|
||||||
placed_ts = order.placed_at.strftime('%Y-%m-%dT%H:%M:%SZ') if (order and getattr(order, 'placed_at', None)) else '2026-10-09T10:00:00Z'
|
placed_ts = order.placed_at.strftime('%Y-%m-%dT%H:%M:%SZ') if (order and getattr(order, 'placed_at', None)) else '2026-10-09T10:00:00Z'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue