Modelling a Custom Jewellery Order as a State Machine (with Human Approval Gates)
Custom jewellery orders are a nice, small example of why "add a chatbot" is the wrong first move for retail automation. The real problem is state: the customer wants to know where their order is, and the answer lives in someone's head or a paper order book. This post shows a tiny state machine for a custom order, with approval gates on the steps that touch money or promises. It is the pattern we…
Custom jewellery orders pose challenges for retail automation due to the state of the order and the human approvals required. This state machine outlines the progression of a custom jewellery order, with gates that require human approval before certain steps involving money or promises. The states in the machine include ENQUIRY, DESIGN_SHARED, DESIGN_APPROVED, ADVANCE_RECEIVED, IN_MAKING, READY_FOR_TRIAL, ALTERATION (optional), READY_FOR_PICKUP, and DELIVERED. Additionally, there are two side exits: DELAYED (needing a human message) and CANCELLED.
The rules governing the transitions between states require that every transition is made by a named staff member. Some transitions automatically trigger a customer message using an approved template, while others only draft a message that must be approved by a person before proceeding. The approvals apply to any message about price, balance due, or delay.
The code utilizes dataclasses for the Order object, a dictionary for the transition rules, and defines two sets: AUTO_SEND for states that automatically send customer messages, and NEEDS_APPROVAL for states that require human approval. The Order class maintains a history of state transitions and allows for moving between states through the move method, which checks for valid transitions, updates the order's state and history, and formats customer messages for appropriate actions.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.