Repository navigation
Conversation
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #252
Exact Before-Fix Reproduction Numbers
PATCH /api/orders/:id/statuswith{ status: 'cancelled' }): Stock -> 12 (+2 unwanted inventory inflation).ready->preparing,served->preparing,served->ready) and terminal status changes (e.g.cancelled->preparing) returned HTTP 200 and mutatedorders.statusbackward.preparingstatus was voided (creating avoideditem and avoid_adjustmentline). When the whole order was cancelled, stock increased from 11 -> 12, restocking an item whose ingredients were already cooked and consumed.Verified Subclaim Matrix
void_adjustmentandvoideditems.Order Lifecycle Transition Matrix
In
main/routes/orders.ts, order status transitions are strictly governed by an explicit state transition matrix:pending:['preparing', 'ready', 'served', 'completed', 'cancelled']preparing:['ready', 'served', 'completed', 'cancelled']ready:['served', 'completed', 'cancelled']served:['completed', 'cancelled']completed:[](terminal)cancelled:[](terminal)Behavioral Rules:
status === currentOrder.status) are safe idempotent no-ops (HTTP 200 returning current order without repeating side effects).ready->preparing,served->ready) and invalid terminal transitions are rejected with HTTP 400 (Cannot transition order status from '<current>' to '<target>').pending->ready,pending->completed) and cancellation from any active state remain fully supported.Final Inventory / Restock Rules for Item Statuses
On whole-order cancellation:
pending,preparing,ready,served,completed: Eligible for one-time inventory restoration ifproduct.track_inventoryis enabled and item has not already been cancelled/voided.cancelled: Excluded from restocking (stock was already restored when item was individually cancelled).voided: Excluded from restocking (ingredients were physically cooked/consumed in kitchen).void_adjustment: Excluded from restocking (accounting adjustment line only).On item cancellation & restoration:
PATCH /api/orders/:orderId/items/:itemId/cancel:isInProgressVoidis determined strictly bycurrentItem.status(preparing/ready), NOT parent order status. An item that is stillpendingin apreparingparent order follows pending cancellation & restock contract (+1 stock, status =cancelled, novoid_adjustment).PATCH /api/orders/:orderId/items/:itemId/restore:cancelleditems can be restored.product.stock_quantity >= item.quantity), re-deducts stock, and marks itempending. If stock is insufficient, returns HTTP 400.Files Changed
main/routes/orders.ts: EnforcesVALID_TRANSITIONSmatrix, re-reads order insidewithTxn(), and filters restock candidates.main/routes/index.ts: StrictcurrentItem.statusvoid semantics, idempotent item cancel/restore with stock checks, and excluded voided items from auto-cancel restock.package.json: Addedtest:issue-252script and registeredbash tests/run-test.sh npm run test:issue-252in the mainnpm testchain.tests/issue-252-order-lifecycle-inventory.test.ts: Added 50-assertion integration regression test suite (including concurrent cancellation HTTP test case) with real exit code handling.Tests Run & Exact Results
git diff --check: 0 errors.npm run test:issue-252: 50/50 assertion suites PASSED (100%)npm run test:integration-lifecycle: 18/18 PASSED (100%)npm run test:cancel-override: 14/14 PASSED (100%)npm run test:issue-24: PASSED (100%)npm run test:kds-integration: PASSED (100%)npm run test:kds-contract: PASSED (100%)npm run test:integration-reconciliation: PASSED (100%)npm run test:integration-payments: PASSED (100%)npm run build: Compiled cleanlynpm run lint:backend: 0 errorsRisk & Testing Scope
/api/order-items/:itemId/status), concurrent HTTP cancellation requests, and bill reconciliation.Important
This PR requires maintainer review before merge. Do not auto-merge.