This commit is contained in:
Marek Lenczewski
2026-04-18 07:41:09 +02:00
parent 18fc50c75b
commit bf6f5456d6
63 changed files with 288 additions and 21 deletions

View File

@@ -216,10 +216,49 @@ CATEGORY_CREATE = ToolSpec(
)
# ---- orders.update_status -----------------------------------------
def _handler_order_status(args: dict, db: Session) -> dict:
from apps.orders.models import Order, OrderStatusHistory
order_id = int(args["id"])
o = db.get(Order, order_id)
if not o:
raise ValueError(f"Order {order_id} not found")
new_status = args["status"]
note = _coalesce(args.get("note"), "")
o.status = new_status
db.add(OrderStatusHistory(order_id=order_id, status=new_status, note=note))
db.commit()
event_bus.publish("order.status_changed", {"id": order_id, "status": new_status}, db=db)
return {"id": order_id, "status": new_status}
ORDER_STATUS = ToolSpec(
name="orders.update_status",
description="Change the status of an order (e.g. paid, packed, shipped, delivered, cancelled).",
args_schema={
"type": "object",
"required": ["id", "status"],
"properties": {
"id": {"type": "integer", "description": "Order ID"},
"status": {
"type": "string",
"description": "New status: paid, packed, shipped, delivered, cancelled",
},
"note": {"type": "string", "description": "Optional note"},
},
},
handler=_handler_order_status,
examples=[{"id": 1, "status": "shipped", "note": "DHL versendet"}],
)
# ---- registration -------------------------------------------------
ALL_TOOLS = [SETTINGS_UPDATE, PRODUCT_CREATE, PRODUCT_UPDATE, CATEGORY_CREATE]
ALL_TOOLS = [SETTINGS_UPDATE, PRODUCT_CREATE, PRODUCT_UPDATE, CATEGORY_CREATE, ORDER_STATUS]
def register_all() -> None: