Update mutable fields on an existing work order.
(
db,
wonum: str,
site_id: str,
description: Optional[str] = None,
priority: Optional[int] = None,
location: Optional[str] = None,
asset_num: Optional[str] = None,
notes: Optional[str] = None,
failure_code: Optional[str] = None,
)
| 416 | |
| 417 | |
| 418 | async def update_workorder( |
| 419 | db, |
| 420 | wonum: str, |
| 421 | site_id: str, |
| 422 | description: Optional[str] = None, |
| 423 | priority: Optional[int] = None, |
| 424 | location: Optional[str] = None, |
| 425 | asset_num: Optional[str] = None, |
| 426 | notes: Optional[str] = None, |
| 427 | failure_code: Optional[str] = None, |
| 428 | ) -> Dict[str, Any]: |
| 429 | """Update mutable fields on an existing work order.""" |
| 430 | with Timer() as t: |
| 431 | doc = await db.get(_doc_id(site_id, wonum)) |
| 432 | if not doc: |
| 433 | return error(f"Work order '{wonum}' not found", "NOT_FOUND") |
| 434 | if description is not None: |
| 435 | doc["description"] = description[:100] |
| 436 | if priority is not None: |
| 437 | doc["wopriority"] = priority |
| 438 | if location is not None: |
| 439 | doc["location"] = location |
| 440 | if asset_num is not None: |
| 441 | doc["assetnum"] = asset_num |
| 442 | if notes is not None: |
| 443 | doc["description_longdescription"] = notes |
| 444 | if failure_code is not None: |
| 445 | doc["failurecode"] = failure_code |
| 446 | |
| 447 | await db.put(doc) |
| 448 | return envelope(_public(doc), duration_ms=t_ms(t)) |
| 449 | |
| 450 | |
| 451 | async def _change_status( |