Skip to content

Orders: Cannot remove/cancel individual items once they move to 'preparing' or 'ready' — design decision needed #150

Closed

Description

@khaira777

Summary

Currently, a manager or owner can cancel (remove) individual items from an active order — but only while those items are still in pending status. Once kitchen staff mark an item as preparing or ready on the KDS, the trash icon disappears from the Orders page and there is no way to remove that item without first going to the KDS and reverting its status back to pending.

This is a real operational friction point: a customer changes their mind after the kitchen has already started on their food, or a manager wants to comp an item after it's been cooked.


Current behaviour (verified in code)

Frontend — Orders page

// frontend/src/app/(dashboard)/orders/page.tsx ~L986
{item.status === 'pending' && isOwnerOrManager && !paid && (
  <button onClick={() => deleteItem(order.id, item.id)} ...>
    <Trash2 size={14} />
  </button>
)}

The item.status === 'pending' guard is hard-coded. There is no path for a manager to remove a preparing or ready item from the Orders page UI.

Backend — item cancel route

// main/routes/index.ts ~L183
PATCH /api/orders/:orderId/items/:itemId/cancel

Existing precedent — whole-order cancellation

Cancelling a whole order that is in progress already requires a manager PIN override (backend: main/routes/orders.ts ~L568-580). This pattern already exists in the codebase and the UI has a modal that collects the PIN.


Open questions for the team

Q1 — Should item removal in preparing/ready be allowed at all?

Option A — Yes, always (for owner/manager)
Allow it with a confirmation dialog, no PIN. Simple. No new setting. Risk: accidental removals are easy, and there is no audit trail for why items were removed after cooking started.

Option B — Yes, but require a manager PIN (like whole-order cancel)
Extend the existing override_pin pattern. When the item is preparing or ready, the trash icon opens a PIN dialog instead of a plain confirmation. The backend validates the PIN against any active owner/manager account. Consistent with existing UX precedent. Adds friction on purpose.

Option C — Owner-configurable setting in Settings → KDS
Add a toggle: "Allow item removal after kitchen has started" (default: off). If off, the current behaviour is unchanged. If on, item removal in preparing/ready status is allowed (possibly still requiring a PIN — could be a second toggle or always required). More flexible for different businesses.

Option D — Block it entirely
Keep the current hard block. Managers must go to KDS, revert the item to pending, then come back to the Orders page to remove it. Safest for kitchen workflow but terrible UX.

Q2 — If we allow it, should there be an audit log entry?

Right now, item cancellations are recorded via cloudSync.recordOrderChanged(orderId, 'order.item_cancelled') but there is no free-text reason captured for in-progress items the way whole-order cancellation captures a cancellation_reason. Should a reason be required?

Q3 — Should the KDS reflect the removal immediately?

Currently, deleteItem calls notifyKdsUpdate() on the backend, so the KDS will refresh. But if the item was already showing as preparing on the kitchen screen, the card will simply disappear. Should there be a visual indicator or sound on the KDS side when an in-progress item is voided? (Out of scope for this issue, but worth noting.)

Q4 — What roles should this gate apply to?

Currently both owner and manager can remove pending items. Should removing an in-progress item require strictly owner-level, or is manager sufficient (with or without a PIN)?


Recommendation

The PIN override approach (Option B) is the cleanest for this codebase because:

  1. The pattern already exists — CancelModal has an overridePin field, the backend already has checkPinRateLimit and PIN validation logic in routes/orders.ts.
  2. It adds meaningful friction without a new Settings page.
  3. It is self-documenting: the PIN prompt message can say "Item is in progress — manager PIN required to remove".

The settings toggle (Option C) becomes relevant if different businesses have very different policies (e.g. a QSR might never want to allow it; a sit-down restaurant might always want it). This could be deferred to a follow-up.

If Option B is chosen, the changes needed are:

  • Frontend: change the item.status === 'pending' guard to also show the trash button for preparing/ready items, but route those into a PIN-collection modal instead of the plain confirm dialog.
  • Backend /items/:itemId/cancel: add an optional override_pin field; if the item's current status is preparing or ready, require the PIN (same validation as the order-level cancel).

Files to change (if Option B)

  • frontend/src/app/(dashboard)/orders/page.tsx — deleteItem function (~L458), item trash button condition (~L986), extend CancelModal or add a separate ItemCancelModal state
  • main/routes/index.ts — PATCH /api/orders/:orderId/items/:itemId/cancel handler (~L183), add override_pin check when item status is preparing/ready

Related

  • Whole-order cancel with PIN: main/routes/orders.ts ~L568-590
  • Item cancel backend: main/routes/index.ts ~L183-303
  • KDS update notification: both routes call notifyKdsUpdate() after mutation

Activity

  1. added
    enhancement
    question
    area:frontend
    area:backend
    on Jul 24, 2026
  2. itsbkm commented on Jul 25, 2026

    @itsbkm
    Contributor

    Decision — void flow for in-progress items

    Resolves Q1–Q4 above: Option B, extended (manager-PIN-gated), with concrete financial/inventory/KDS behavior spelled out below.

    The existing pending-item workflow is unchanged — trash icon, immediate delete, no PIN, exactly as today. This only adds a new path for items already preparing/ready.

    What "void" does

    1. Bill — instead of removing the line, add a negative line item for the same amount. The bill total reflects the refund/comp, but there's a record the item was ordered and then voided, rather than it silently vanishing from the bill.
    2. Inventory — deduct inventory for the voided item as if it had been served. It was already prepared, so the ingredients are already consumed; voiding doesn't restock them.
    3. KDS — the item card gets a red strikethrough, its stage becomes locked (kitchen can no longer advance/change its status), and it auto-disappears from the KDS board 15 minutes after being voided.
    4. Manager PIN required — reuses the existing override_pin pattern from whole-order cancel (checkPinRateLimit + PIN validation in main/routes/orders.ts ~L568-590), not a new mechanism.

    UI

    • Orders page, per-item action icon:
      • pending item → unchanged: trash icon (Trash2), immediate delete, no PIN.
      • preparing/ready item → same icon slot, but shows 🚫 (U+1F6AB) instead of trash, and opens the PIN-gated void flow instead of a plain confirm.

    Implementation sketch

    • main/routes/index.ts — PATCH /api/orders/:orderId/items/:itemId/cancel gains an override_pin field. When the item's current status is preparing/ready, the PIN is required and validated. On success: insert the negative bill line, deduct inventory, and mark the item voided with a voided_at timestamp instead of hard-deleting it.
    • New item status voided, distinct from cancelled (which currently only covers pre-kitchen removal). Item stage-change endpoints must reject any transition once an item is voided.
    • KdsTabsView.tsx / KdsKanbanBoard.tsx — render voided items with a red strikethrough and disable their stage-advance controls.
    • KDS order query — filter out items where voided_at is more than 15 minutes old (same shape as other time-windowed KDS filtering already in the codebase).
    • Orders page — deleteItem stays as-is for pending; a new voidItem path reuses the CancelModal PIN-collection pattern and calls the extended cancel endpoint.

    Out of scope

    • Whole-order cancellation flow — untouched.
    • Settings toggle (Option C from above) — not building this now; PIN gating is the only control needed per this decision.
  3. itsbkm commented on Jul 26, 2026

    @itsbkm
    Contributor

    Reviewed the fix on main (commit fabbe65). It covers the agreed void flow:

    • pending items remain on the existing cancel path with no PIN
    • preparing/ready items open a manager-PIN-gated void flow from Orders
    • backend validates override_pin with the existing owner/manager PIN pattern and rate limit
    • voiding keeps the original line, adds a negative void_adjustment bill line, marks the original item voided, and sets voided_at
    • KDS REST, standalone KDS, and websocket payloads exclude the adjustment line, show voided items briefly, then age them off after 15 minutes
    • KDS/order item status routes reject changes once an item is voided

    One note: the final implementation leaves inventory deducted / does not restock, which matches the operational intent that the item was already prepared/consumed.

    Verification run on 2026-07-26:

    • frontend: npm run lint passed
    • root: npm run build passed
    • root: npm test passed

    Closing as fixed.

  4. itsbkm commented on Jul 26, 2026

    @itsbkm
    Contributor

    Clarification on inventory wording:

    Inventory handling is intentional and status-dependent:

    • If an item is removed while still pending, it follows the existing cancel path and inventory is not treated as consumed by that cancellation.
    • If an item has already reached preparing or ready, voiding it does not restock inventory because the item has already been prepared/consumed operationally.
    • The bill keeps the original item line and adds a matching negative Void: <item name> adjustment line, so the customer can clearly see that the item was revoked/comped instead of it silently disappearing.

    So the intended model is: pre-kitchen cancellation removes the item; post-kitchen void keeps the consumed inventory state and offsets the customer-facing bill with a negative line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendarea:frontendenhancementquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions