# Order status times live on the order, not in a history table

The order status time report (تقرير معدل تغيير حالة الطلبات, 2026-10-28) needs to know when
each order reached each delivery status. We keep **one time per status on `orders`**
(`confirmed_at`, `delivered_date` and `cancelled_at` already existed; `picked_up_at` and
`on_the_way_at` were added), written by the `Order` model hook so every screen fills them,
instead of a status history table with one row per change. The report measures the median
time between consecutive statuses, and for that the latest time of each status on the
route the order is on now is enough; the business asked for that and not for the
back-and-forth.

## Considered Options

- **A status history table** (`order_status_changes`: from, to, time, who, screen). It would
  keep backward moves, repeated steps and who made each change, and allow a "most common
  routes" table. Rejected: more than the report needs, and a second record of the status to
  keep in step with `orders`.

## Consequences

- Reaching a status again replaces its time; going back clears the times of every later
  status (as `confirmed_at` already was on a move back to pending). A skipped status has no
  time, and the next one is measured from the latest earlier status that has one.
- Nothing records how often an order went back and forth or who moved it at each step. If
  that is ever wanted, it needs the history table above; the columns cannot be turned into
  one after the fact.
- `cancelled_at` also holds the time of a full return; the delivery status tells them apart.
- The report works on the Combined Order (see "Combined status time" in `CONTEXT.md`); the
  times stay on the Child Orders, where the status actually changes.
- Older orders: `picked_up_at` / `on_the_way_at` are copied once from the audit log (kept
  since about 2026-09-19), and so is `cancelled_at` for cancels made through the status
  dropdown, which did not write it. Steps run by the Kapitano Logistic sync before deploy
  wrote no audit and stay empty.
