demo seed change
This commit is contained in:
@@ -91,8 +91,11 @@ async def get_expected_deliveries(
|
||||
|
||||
# Add date filters
|
||||
if include_overdue:
|
||||
# Include any delivery from past until end_date
|
||||
# Include deliveries from last 48 hours (recent overdue) until end_date
|
||||
# This ensures we only show truly recent overdue deliveries, not ancient history
|
||||
start_date = now - timedelta(hours=48)
|
||||
query = query.where(
|
||||
PurchaseOrder.expected_delivery_date >= start_date,
|
||||
PurchaseOrder.expected_delivery_date <= end_date
|
||||
)
|
||||
else:
|
||||
@@ -149,13 +152,22 @@ async def get_expected_deliveries(
|
||||
# Default delivery window is 4 hours
|
||||
delivery_window_hours = 4
|
||||
|
||||
# Ensure expected delivery date is timezone-aware and in UTC format
|
||||
expected_delivery_utc = po.expected_delivery_date
|
||||
if expected_delivery_utc and expected_delivery_utc.tzinfo is None:
|
||||
# If naive datetime, assume it's UTC (this shouldn't happen with proper DB setup)
|
||||
expected_delivery_utc = expected_delivery_utc.replace(tzinfo=timezone.utc)
|
||||
elif expected_delivery_utc and expected_delivery_utc.tzinfo is not None:
|
||||
# Convert to UTC if it's in another timezone
|
||||
expected_delivery_utc = expected_delivery_utc.astimezone(timezone.utc)
|
||||
|
||||
delivery_dict = {
|
||||
"po_id": str(po.id),
|
||||
"po_number": po.po_number,
|
||||
"supplier_id": str(po.supplier_id),
|
||||
"supplier_name": supplier_name,
|
||||
"supplier_phone": supplier_phone,
|
||||
"expected_delivery_date": po.expected_delivery_date.isoformat(),
|
||||
"expected_delivery_date": expected_delivery_utc.isoformat() if expected_delivery_utc else None,
|
||||
"delivery_window_hours": delivery_window_hours,
|
||||
"status": po.status.value,
|
||||
"line_items": line_items,
|
||||
@@ -187,4 +199,4 @@ async def get_expected_deliveries(
|
||||
tenant_id=tenant_id,
|
||||
exc_info=True
|
||||
)
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
|
||||
Reference in New Issue
Block a user