129 lines
4.2 KiB
Python
129 lines
4.2 KiB
Python
"""Wave 0 Transport Fleet & Carrier Registry Mock Adapter for Iteration 04.
|
|
|
|
Pre-seeds deterministic carrier and owned truck registry with payload capacities,
|
|
fitness certificates, and maintenance status flags for dispatch gating.
|
|
"""
|
|
from datetime import date, datetime
|
|
from decimal import Decimal
|
|
from typing import Dict, Any, List, Optional, Tuple
|
|
|
|
|
|
VEHICLES = [
|
|
{
|
|
"id": "VEH-001",
|
|
"reg_no": "MP-43-G-1234",
|
|
"make_model": "Tata Signa 2823",
|
|
"payload_capacity_mt": Decimal("25.000"),
|
|
"ownership_type": "Own",
|
|
"transporter_name": "Mandi In-House Fleet",
|
|
"status": "Available",
|
|
"fitness_expiry": "2027-12-31",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "VEH-002",
|
|
"reg_no": "MP-14-AB-5678",
|
|
"make_model": "Ashok Leyland Ecomet",
|
|
"payload_capacity_mt": Decimal("16.000"),
|
|
"ownership_type": "Contract",
|
|
"transporter_name": "Shree Ganesh Roadlines",
|
|
"status": "Available",
|
|
"fitness_expiry": "2026-11-30",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "VEH-003",
|
|
"reg_no": "RJ-09-GA-9012",
|
|
"make_model": "BharatBenz 3528C",
|
|
"payload_capacity_mt": Decimal("32.000"),
|
|
"ownership_type": "Contract",
|
|
"transporter_name": "Marwar Transport Corp",
|
|
"status": "On Route",
|
|
"fitness_expiry": "2027-05-15",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "VEH-004",
|
|
"reg_no": "MP-09-HH-3456",
|
|
"make_model": "Eicher Pro 3015",
|
|
"payload_capacity_mt": Decimal("10.500"),
|
|
"ownership_type": "Own",
|
|
"transporter_name": "Mandi In-House Fleet",
|
|
"status": "Maintenance",
|
|
"fitness_expiry": "2026-08-01",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "VEH-005",
|
|
"reg_no": "MP-43-K-7890",
|
|
"make_model": "Tata LPT 1618",
|
|
"payload_capacity_mt": Decimal("15.000"),
|
|
"ownership_type": "Contract",
|
|
"transporter_name": "Malwa Logistics",
|
|
"status": "Available",
|
|
"fitness_expiry": "2024-01-01",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "veh-demo-03",
|
|
"reg_no": "RJ20GA3311",
|
|
"make_model": "BharatBenz 2823R",
|
|
"payload_capacity_mt": Decimal("28.000"),
|
|
"ownership_type": "Contract",
|
|
"transporter_name": "Rajasthan Freight Lines",
|
|
"status": "Available",
|
|
"fitness_expiry": "2026-10-01",
|
|
"is_active": True,
|
|
},
|
|
]
|
|
|
|
|
|
class FleetMock:
|
|
"""Mock helper for fleet vehicle registry and dispatch eligibility gating."""
|
|
|
|
@classmethod
|
|
def get_vehicle(cls, vehicle_identifier: str) -> Optional[Dict[str, Any]]:
|
|
"""Look up by vehicle ID or registration number."""
|
|
ident = vehicle_identifier.strip().upper()
|
|
for v in VEHICLES:
|
|
if v["id"].upper() == ident or v["reg_no"].upper() == ident:
|
|
return dict(v)
|
|
return None
|
|
|
|
@classmethod
|
|
def list_vehicles(cls, status: Optional[str] = None) -> List[Dict[str, Any]]:
|
|
results = []
|
|
for v in VEHICLES:
|
|
if status is None or v["status"].lower() == status.lower():
|
|
results.append(dict(v))
|
|
return results
|
|
|
|
@classmethod
|
|
def check_dispatch_eligibility(
|
|
cls, vehicle_identifier: str, reference_date: Optional[date] = None
|
|
) -> Tuple[bool, Optional[str]]:
|
|
"""Validates if vehicle can be assigned to an outbound consignment.
|
|
|
|
Enforces:
|
|
- Must exist in registry.
|
|
- Status must not be Maintenance or On Route.
|
|
- Fitness certificate must not be expired.
|
|
"""
|
|
v = cls.get_vehicle(vehicle_identifier)
|
|
if not v:
|
|
return False, f"Vehicle '{vehicle_identifier}' not found in registry"
|
|
|
|
if v["status"] == "Maintenance":
|
|
return False, f"Vehicle '{v['reg_no']}' is currently under Maintenance"
|
|
|
|
if v["status"] == "On Route":
|
|
return False, f"Vehicle '{v['reg_no']}' is currently On Route"
|
|
|
|
today = reference_date or date.today()
|
|
expiry_date = datetime.strptime(v["fitness_expiry"], "%Y-%m-%d").date()
|
|
if expiry_date < today:
|
|
return False, f"Vehicle '{v['reg_no']}' fitness certificate expired on {v['fitness_expiry']}"
|
|
|
|
return True, None
|
|
|