Create a new work order (status WAPPR). Optionally pin `wonum` for reproducible ids and attach `aob_source` provenance (the agent/trigger that generated it).
(
db,
description: str,
asset_num: str,
site_id: str,
priority: int = 3,
work_type: str = "CM",
reported_by: Optional[str] = None,
location: Optional[str] = None,
notes: Optional[str] = None,
wonum: Optional[str] = None,
aob_source: Optional[Dict[str, Any]] = None,
now: Optional[datetime] = None,
)
| 357 | # Write tools |
| 358 | # --------------------------------------------------------------------------- # |
| 359 | async def create_workorder( |
| 360 | db, |
| 361 | description: str, |
| 362 | asset_num: str, |
| 363 | site_id: str, |
| 364 | priority: int = 3, |
| 365 | work_type: str = "CM", |
| 366 | reported_by: Optional[str] = None, |
| 367 | location: Optional[str] = None, |
| 368 | notes: Optional[str] = None, |
| 369 | wonum: Optional[str] = None, |
| 370 | aob_source: Optional[Dict[str, Any]] = None, |
| 371 | now: Optional[datetime] = None, |
| 372 | ) -> Dict[str, Any]: |
| 373 | """Create a new work order (status WAPPR). Optionally pin `wonum` for reproducible ids |
| 374 | and attach `aob_source` provenance (the agent/trigger that generated it).""" |
| 375 | if not description or not asset_num or not site_id: |
| 376 | return error( |
| 377 | "description, asset_num, and site_id are required", "VALIDATION_ERROR" |
| 378 | ) |
| 379 | if not 1 <= priority <= 5: |
| 380 | return error("priority must be between 1 and 5", "VALIDATION_ERROR") |
| 381 | if work_type not in WORKTYPES: |
| 382 | return error(f"work_type must be one of {WORKTYPES}", "VALIDATION_ERROR") |
| 383 | |
| 384 | with Timer() as t: |
| 385 | now = now or datetime.now(timezone.utc) |
| 386 | won = wonum or await db.next_wonum(site_id) |
| 387 | doc: Dict[str, Any] = { |
| 388 | "_id": _doc_id(site_id, won), |
| 389 | "type": "workorder", |
| 390 | "schema_version": "1.0.0", |
| 391 | "wonum": won, |
| 392 | "siteid": site_id.upper(), |
| 393 | "description": description[:100], |
| 394 | "assetnum": asset_num, |
| 395 | "wopriority": priority, |
| 396 | "worktype": work_type, |
| 397 | "status": "WAPPR", |
| 398 | "reportdate": _iso(now), |
| 399 | } |
| 400 | if reported_by: |
| 401 | doc["reportedby"] = reported_by |
| 402 | if location: |
| 403 | doc["location"] = location |
| 404 | if notes: |
| 405 | doc["description_longdescription"] = notes |
| 406 | if aob_source: |
| 407 | doc["aob_source"] = aob_source |
| 408 | await db.put(doc) |
| 409 | return envelope(_public(doc), duration_ms=t_ms(t)) |
| 410 | |
| 411 | |
| 412 | # Alias matching the AssetOpsBench WO Agent's tool name. |
no test coverage detected