142 lines
4.4 KiB
Python
142 lines
4.4 KiB
Python
"""Wave 0 Warehouse Master & Capacity Seeder for Iteration 04.
|
|
|
|
Pre-seeds canonical warehouses, storage capacities, godown chambers,
|
|
and initial stock balance fixtures for multi-godown stock ledger testing.
|
|
"""
|
|
from decimal import Decimal
|
|
from typing import Dict, Any, List, Optional
|
|
import uuid
|
|
|
|
WAREHOUSES = [
|
|
{
|
|
"id": "WH-01",
|
|
"name": "Neemuch Main Yard",
|
|
"city": "Neemuch",
|
|
"state": "Madhya Pradesh",
|
|
"capacity_mt": Decimal("2000.000"),
|
|
"chambers": ["Stack A1", "Stack A2", "Stack B1", "Stack B2"],
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "WH-02",
|
|
"name": "Neemuch North Godown",
|
|
"city": "Neemuch",
|
|
"state": "Madhya Pradesh",
|
|
"capacity_mt": Decimal("1500.000"),
|
|
"chambers": ["Stack C1", "Stack C2"],
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "WH-03",
|
|
"name": "Mandsaur Transit Godown",
|
|
"city": "Mandsaur",
|
|
"state": "Madhya Pradesh",
|
|
"capacity_mt": Decimal("1000.000"),
|
|
"chambers": ["Stack T1", "Stack T2"],
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"id": "WH-04",
|
|
"name": "Indore Buffer Depot",
|
|
"city": "Indore",
|
|
"state": "Madhya Pradesh",
|
|
"capacity_mt": Decimal("3000.000"),
|
|
"chambers": ["Stack D1", "Stack D2", "Stack D3"],
|
|
"is_active": True,
|
|
},
|
|
]
|
|
|
|
INITIAL_STOCK = [
|
|
{
|
|
"warehouse_id": "WH-01",
|
|
"commodity_id": "c0a80123-0000-0000-0000-000000000002", # Chana
|
|
"variety": "Desi",
|
|
"grade": "FAQ",
|
|
"opening_mt": Decimal("450.000"),
|
|
"inward_mt": Decimal("75.500"),
|
|
"outward_mt": Decimal("25.000"),
|
|
"closing_mt": Decimal("500.500"),
|
|
"closing_bags": 10010,
|
|
},
|
|
{
|
|
"warehouse_id": "WH-01",
|
|
"commodity_id": "c0a80123-0000-0000-0000-000000000001", # Soyabean
|
|
"variety": "Yellow Desi",
|
|
"grade": "FAQ",
|
|
"opening_mt": Decimal("600.000"),
|
|
"inward_mt": Decimal("120.000"),
|
|
"outward_mt": Decimal("80.000"),
|
|
"closing_mt": Decimal("640.000"),
|
|
"closing_bags": 12800,
|
|
},
|
|
{
|
|
"warehouse_id": "WH-02",
|
|
"commodity_id": "c0a80123-0000-0000-0000-000000000003", # Mustard
|
|
"variety": "Black",
|
|
"grade": "Bold",
|
|
"opening_mt": Decimal("300.000"),
|
|
"inward_mt": Decimal("50.000"),
|
|
"outward_mt": Decimal("10.000"),
|
|
"closing_mt": Decimal("340.000"),
|
|
"closing_bags": 6800,
|
|
},
|
|
{
|
|
"warehouse_id": "WH-03",
|
|
"commodity_id": "c0a80123-0000-0000-0000-000000000004", # Wheat
|
|
"variety": "Lokwan",
|
|
"grade": "FAQ",
|
|
"opening_mt": Decimal("250.000"),
|
|
"inward_mt": Decimal("40.000"),
|
|
"outward_mt": Decimal("25.250"),
|
|
"closing_mt": Decimal("264.750"),
|
|
"closing_bags": 5295,
|
|
},
|
|
]
|
|
|
|
|
|
class WarehouseMock:
|
|
"""Mock helper for warehouse locations, capacities and stock balances."""
|
|
|
|
@classmethod
|
|
def get_warehouse(cls, warehouse_id: str) -> Optional[Dict[str, Any]]:
|
|
for w in WAREHOUSES:
|
|
if w["id"] == warehouse_id:
|
|
return dict(w)
|
|
return None
|
|
|
|
@classmethod
|
|
def list_warehouses(cls) -> List[Dict[str, Any]]:
|
|
return [dict(w) for w in WAREHOUSES]
|
|
|
|
@classmethod
|
|
def get_initial_stock(cls, warehouse_id: str, commodity_id: Optional[str] = None) -> List[Dict[str, Any]]:
|
|
results = []
|
|
for s in INITIAL_STOCK:
|
|
if s["warehouse_id"] == warehouse_id:
|
|
if commodity_id is None or s["commodity_id"] == commodity_id:
|
|
results.append(dict(s))
|
|
return results
|
|
|
|
@classmethod
|
|
def calculate_utilization(cls, warehouse_id: str, current_stock_mt: Decimal) -> Dict[str, Any]:
|
|
wh = cls.get_warehouse(warehouse_id)
|
|
if not wh:
|
|
raise ValueError(f"Warehouse {warehouse_id} not found")
|
|
cap = wh["capacity_mt"]
|
|
util_pct = (current_stock_mt / cap) * Decimal("100.0") if cap > Decimal("0") else Decimal("0.0")
|
|
return {
|
|
"warehouse_id": warehouse_id,
|
|
"name": wh["name"],
|
|
"city": wh["city"],
|
|
"capacity_mt": cap,
|
|
"current_stock_mt": current_stock_mt,
|
|
"utilization_pct": round(util_pct, 2),
|
|
"warning": util_pct > Decimal("85.0"),
|
|
"status": "CAPACITY_WARNING" if util_pct > Decimal("85.0") else "NORMAL",
|
|
}
|
|
|
|
|
|
warehouse_mock = WarehouseMock()
|
|
|
|
|