phase-3: breakdown and complaint register with calculations and permissions
This commit is contained in:
@@ -147,6 +147,46 @@ SETTINGS_SCHEMA: list[dict[str, Any]] = [
|
||||
"max": None,
|
||||
"options": ["in_house", "outsourced"],
|
||||
},
|
||||
{
|
||||
"key": "complaint_no_prefix",
|
||||
"type": "str",
|
||||
"default": "CMP",
|
||||
"label": "Complaint Number Prefix",
|
||||
"description": "Prefix used when generating sequential breakdown complaint numbers (e.g. CMP-2026-0001).",
|
||||
"min": None,
|
||||
"max": None,
|
||||
"options": None,
|
||||
},
|
||||
{
|
||||
"key": "critical_complaint_sets_under_repair",
|
||||
"type": "bool",
|
||||
"default": True,
|
||||
"label": "Critical Complaint Marks Asset Under Repair",
|
||||
"description": "Automatically set asset status to under_repair when a critical breakdown complaint is registered or reopened.",
|
||||
"min": None,
|
||||
"max": None,
|
||||
"options": None,
|
||||
},
|
||||
{
|
||||
"key": "response_start",
|
||||
"type": "enum",
|
||||
"default": "registered_at",
|
||||
"label": "Response Time Start Milestone",
|
||||
"description": "Timestamp used as the starting point for biomedical response time calculation.",
|
||||
"min": None,
|
||||
"max": None,
|
||||
"options": ["registered_at", "received_at"],
|
||||
},
|
||||
{
|
||||
"key": "downtime_end_milestone",
|
||||
"type": "enum",
|
||||
"default": "restored_at",
|
||||
"label": "Downtime End Milestone",
|
||||
"description": "Milestone timestamp that stops the equipment downtime clock.",
|
||||
"min": None,
|
||||
"max": None,
|
||||
"options": ["attended_at", "restored_at", "closed_at"],
|
||||
},
|
||||
]
|
||||
|
||||
SETTINGS_BY_KEY: dict[str, dict[str, Any]] = {item["key"]: item for item in SETTINGS_SCHEMA}
|
||||
@@ -243,15 +283,15 @@ def ensure_default_settings(db: Session) -> None:
|
||||
db.flush()
|
||||
|
||||
|
||||
def get_setting_value(db: Session, key: str) -> Any:
|
||||
def get_setting_value(db: Session, key: str, default: Any = None) -> Any:
|
||||
spec = SETTINGS_BY_KEY.get(key)
|
||||
row = db.query(Setting).filter(Setting.key == key).first()
|
||||
if row is None:
|
||||
return spec["default"] if spec else None
|
||||
return spec["default"] if spec else default
|
||||
try:
|
||||
return json.loads(row.value_json)
|
||||
except (ValueError, TypeError):
|
||||
return spec["default"] if spec else None
|
||||
return spec["default"] if spec else default
|
||||
|
||||
|
||||
def get_demo_as_of_date(db: Session) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user