c_agri_trade/project_code/sandbox/master_data_mock.py

186 lines
5.2 KiB
Python

"""Wave 0 Master Data Mock Adapter for Iteration 03.
Pre-seeds deterministic, canonical master data fixtures for standard Indian Mandi
market yards, commodities, counterparties (suppliers/arhatiyas), and godowns/stacks.
"""
from typing import Dict, Any, List, Optional
import uuid
# Canonical Mandi Yards
MANDI_YARDS = [
{
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"name": "Kota APMC Yard",
"state": "Rajasthan",
"district": "Kota",
"code": "RJ-KTA-01",
"is_active": True
},
{
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6e",
"name": "Unjha APMC Yard",
"state": "Gujarat",
"district": "Mehsana",
"code": "GJ-UNJ-01",
"is_active": True
},
{
"id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6f",
"name": "Indore APMC Yard",
"state": "Madhya Pradesh",
"district": "Indore",
"code": "MP-IND-01",
"is_active": True
}
]
# Canonical Commodities
COMMODITIES = [
{
"id": "c0a80123-0000-0000-0000-000000000001",
"name": "Soyabean",
"code": "SOY",
"standard_grade": "FAQ",
"standard_moisture_max": 10.0,
"standard_foreign_matter_max": 1.5,
"standard_damaged_max": 2.0,
"standard_oil_min": 18.0,
"is_active": True
},
{
"id": "c0a80123-0000-0000-0000-000000000002",
"name": "Chana (Bengal Gram)",
"code": "CHN",
"standard_grade": "FAQ",
"standard_moisture_max": 10.5,
"standard_foreign_matter_max": 1.0,
"standard_damaged_max": 3.0,
"standard_oil_min": 0.0,
"is_active": True
},
{
"id": "c0a80123-0000-0000-0000-000000000003",
"name": "Mustard (Sarson)",
"code": "MST",
"standard_grade": "FAQ",
"standard_moisture_max": 8.0,
"standard_foreign_matter_max": 2.0,
"standard_damaged_max": 2.0,
"standard_oil_min": 42.0,
"is_active": True
},
{
"id": "c0a80123-0000-0000-0000-000000000004",
"name": "Wheat (Lokwan / Sharbati)",
"code": "WHT",
"standard_grade": "FAQ",
"standard_moisture_max": 12.0,
"standard_foreign_matter_max": 1.0,
"standard_damaged_max": 2.0,
"standard_oil_min": 0.0,
"is_active": True
}
]
# Canonical Counterparties (Suppliers / Arhatiyas)
SUPPLIERS = [
{
"id": "a0000000-0000-0000-0000-000000000001",
"name": "Kisan Agro Traders",
"code": "SUP-0042",
"gstin": "24ABCDE1234F1Z5",
"pan": "ABCDE1234F",
"mandi_hub": "Kota APMC Yard",
"status": "ACTIVE",
"default_credit_days": 15
},
{
"id": "a0000000-0000-0000-0000-000000000002",
"name": "Mewar Krishi Sangh",
"code": "SUP-0043",
"gstin": "08MNOPQ9012R1Z9",
"pan": "MNOPQ9012R",
"mandi_hub": "Unjha APMC Yard",
"status": "ACTIVE",
"default_credit_days": 7
},
{
"id": "a0000000-0000-0000-0000-000000000003",
"name": "Defunct Trading Co",
"code": "SUP-INACTIVE",
"gstin": "27GHIJK5678L1Z2",
"pan": "GHIJK5678L",
"mandi_hub": "Indore APMC Yard",
"status": "SUSPENDED",
"default_credit_days": 0
}
]
# Warehouse Godowns and Stacks
GODOWNS = [
{
"id": "d0000000-0000-0000-0000-000000000001",
"name": "Godown 02 - Kota Central Warehouse",
"code": "KTA-GD-02",
"capacity_mt": 1000.0,
"stacks": [
{
"id": "d1000000-0000-0000-0000-000000000001",
"bay_name": "Stack B-04",
"capacity_mt": 100.0,
"current_mt": 45.0,
"is_full": False
},
{
"id": "d1000000-0000-0000-0000-000000000002",
"bay_name": "Stack B-05",
"capacity_mt": 100.0,
"current_mt": 100.0,
"is_full": True
}
]
}
]
class MasterDataMock:
"""In-memory service providing deterministic lookup for master records."""
@classmethod
def get_mandi(cls, mandi_id: str) -> Optional[Dict[str, Any]]:
for m in MANDI_YARDS:
if m["id"] == mandi_id:
return m
return None
@classmethod
def get_commodity(cls, commodity_id: str) -> Optional[Dict[str, Any]]:
for c in COMMODITIES:
if c["id"] == commodity_id:
return c
return None
@classmethod
def get_supplier(cls, supplier_id: str) -> Optional[Dict[str, Any]]:
for s in SUPPLIERS:
if s["id"] == supplier_id:
return s
return None
@classmethod
def get_godown(cls, godown_id: str) -> Optional[Dict[str, Any]]:
for g in GODOWNS:
if g["id"] == godown_id:
return g
return None
@classmethod
def get_stack(cls, godown_id: str, stack_id: str) -> Optional[Dict[str, Any]]:
godown = cls.get_godown(godown_id)
if godown:
for st in godown["stacks"]:
if st["id"] == stack_id:
return st
return None