New alert system and panel de control page
This commit is contained in:
@@ -579,16 +579,74 @@ async def seed_purchase_orders_for_tenant(db: AsyncSession, tenant_id: uuid.UUID
|
||||
po9.notes = "DISPUTED: Quality issue reported - batch rejected, requesting replacement or refund"
|
||||
pos_created.append(po9)
|
||||
|
||||
# ============================================================================
|
||||
# DASHBOARD SHOWCASE SCENARIOS - These create specific alert conditions
|
||||
# ============================================================================
|
||||
|
||||
# 10. PO APPROVAL ESCALATION - Pending for 72+ hours (URGENT dashboard alert)
|
||||
po10 = await create_purchase_order(
|
||||
db, tenant_id, supplier_medium_trust,
|
||||
PurchaseOrderStatus.pending_approval,
|
||||
Decimal("450.00"),
|
||||
created_offset_days=-3, # Created 3 days (72 hours) ago
|
||||
priority="high",
|
||||
items_data=[
|
||||
{"name": "Levadura Seca", "quantity": 50, "unit_price": 6.90, "uom": "kg"},
|
||||
{"name": "Sal Fina", "quantity": 30, "unit_price": 0.85, "uom": "kg"}
|
||||
]
|
||||
)
|
||||
po10.notes = "⚠️ ESCALATED: Pending approval for 72+ hours - Production batch depends on tomorrow morning delivery"
|
||||
pos_created.append(po10)
|
||||
|
||||
# 11. DELIVERY OVERDUE - Expected delivery is 4 hours late (URGENT dashboard alert)
|
||||
delivery_overdue_time = datetime.now(timezone.utc) - timedelta(hours=4)
|
||||
po11 = await create_purchase_order(
|
||||
db, tenant_id, supplier_high_trust,
|
||||
PurchaseOrderStatus.sent_to_supplier,
|
||||
Decimal("850.00"),
|
||||
created_offset_days=-5,
|
||||
items_data=[
|
||||
{"name": "Harina de Trigo T55", "quantity": 500, "unit_price": 0.85, "uom": "kg"},
|
||||
{"name": "Mantequilla sin Sal 82% MG", "quantity": 50, "unit_price": 6.50, "uom": "kg"}
|
||||
]
|
||||
)
|
||||
# Override delivery date to be 4 hours ago (overdue)
|
||||
po11.required_delivery_date = delivery_overdue_time
|
||||
po11.expected_delivery_date = delivery_overdue_time
|
||||
po11.notes = "🔴 OVERDUE: Expected delivery was 4 hours ago - Contact supplier immediately"
|
||||
pos_created.append(po11)
|
||||
|
||||
# 12. DELIVERY ARRIVING SOON - Arriving in 8 hours (TODAY dashboard alert)
|
||||
arriving_soon_time = datetime.now(timezone.utc) + timedelta(hours=8)
|
||||
po12 = await create_purchase_order(
|
||||
db, tenant_id, supplier_medium_trust,
|
||||
PurchaseOrderStatus.sent_to_supplier,
|
||||
Decimal("675.50"),
|
||||
created_offset_days=-2,
|
||||
items_data=[
|
||||
{"name": "Azúcar Moreno", "quantity": 100, "unit_price": 1.80, "uom": "kg"},
|
||||
{"name": "Aceite de Oliva Virgen", "quantity": 50, "unit_price": 8.50, "uom": "l"},
|
||||
{"name": "Miel de Azahar", "quantity": 15, "unit_price": 8.90, "uom": "kg"}
|
||||
]
|
||||
)
|
||||
# Override delivery date to be in 8 hours
|
||||
po12.expected_delivery_date = arriving_soon_time
|
||||
po12.required_delivery_date = arriving_soon_time
|
||||
po12.notes = "📦 ARRIVING SOON: Delivery expected in 8 hours - Prepare for stock receipt"
|
||||
pos_created.append(po12)
|
||||
|
||||
await db.commit()
|
||||
|
||||
logger.info(
|
||||
f"Successfully created {len(pos_created)} purchase orders for tenant",
|
||||
tenant_id=str(tenant_id),
|
||||
pending_approval=3,
|
||||
pending_approval=4, # Updated count (includes escalated PO)
|
||||
approved=2,
|
||||
completed=2,
|
||||
sent_to_supplier=2, # Overdue + arriving soon
|
||||
cancelled=1,
|
||||
disputed=1
|
||||
disputed=1,
|
||||
dashboard_showcase=3 # New POs specifically for dashboard alerts
|
||||
)
|
||||
|
||||
return pos_created
|
||||
|
||||
Reference in New Issue
Block a user