Skip to content

fix(orders): enforce lifecycle transitions and one-time inventory restoration #252

Description

@khaira777

Summary

Order status changes and item cancellation/restore paths do not enforce a transition matrix or one-time inventory adjustment. Repeated terminal requests and void-adjustment rows can make inventory and order state diverge.

Current behavior

  • main/routes/orders.ts:806-925 accepts listed target statuses without validating the current-to-target transition.
  • Repeating status=cancelled on an already-cancelled order can execute the inventory-restoration loop again.
  • Whole-order cancellation includes rows that represent void adjustments.
  • The S6-targeted path in main/routes/index.ts:251-508 has similar cancel/restore status and inventory assumptions.

Expected behavior

Order lifecycle transitions should be explicit and monotonic unless a documented adjustment flow is used. Inventory should be restored at most once and only for quantities that were actually deducted.

Acceptance criteria

  • Define and enforce a current-to-target transition matrix, including terminal states.
  • Re-read order/item state inside the transaction and make repeated requests safe.
  • Exclude void_adjustment and already-processed rows from inventory restoration.
  • Ensure whole-order cancellation and item cancellation/restore cannot create duplicate adjustments.
  • Add tests for repeated cancellation, completed/cancelled sources, voided items, and concurrent requests.

Relevant files

main/routes/orders.ts, main/routes/index.ts, main/routes/order-items.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendBackend (Express/SQLite)bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions