MCPcopy
hub / github.com/IBM/AssetOpsBench / create_workorder

Function create_workorder

src/servers/wo/workorders.py:359–409  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

357# Write tools
358# --------------------------------------------------------------------------- #
359async 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.

Callers 1

generate_work_orderFunction · 0.85

Calls 9

errorFunction · 0.90
TimerClass · 0.90
envelopeFunction · 0.90
_doc_idFunction · 0.85
_isoFunction · 0.85
_publicFunction · 0.85
t_msFunction · 0.85
next_wonumMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected