Repository navigation
fix(orders): guard financial status changes - #1161
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@greptileai review |
[Critical impact] The PR appears safe to merge; no new actionable issue was found.
|
…mat changed files
…te (Shard 2/4)` (`npm run test:authorization-permissions`): - **Invariant violated**: Static source assertions in [`tests/authorization-static-audit.test.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M4YG5QA5XNS987YQ0FE5FHP3/tests/authorization-static-audit.test.ts) checking that `OrderCard` gates item cancellation on `canCancelItems && !isPaid` must tolerate Oxfmt multi-line wrapping across boolean operands. - **Root cause**: When [`frontend/src/components/orders/OrderCard.tsx`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M4YG5QA5XNS987YQ0FE5FHP3/frontend/src/components/orders/OrderCard.tsx) was formatted by Oxfmt in commit `135938d6`, `{canCancelItems && !isPaid && !['completed', 'cancelled'].includes(order.status) && (` was wrapped across multiple lines (`{canCancelItems &&\n !isPaid &&`), causing `assert.match(orderCard, /\{canCancelItems && !isPaid/)` in [`tests/authorization-static-audit.test.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M4YG5QA5XNS987YQ0FE5FHP3/tests/authorization-static-audit.test.ts) to fail. - **Fix**: Updated the regex in [`tests/authorization-static-audit.test.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M4YG5QA5XNS987YQ0FE5FHP3/tests/authorization-static-audit.test.ts) to `/\{canCancelItems &&\s+!isPaid/` and formatted the modified test file with `oxfmt`. - **Verification**: - `npm run test:authorization-permissions` (passed) - `node scripts/ci/check-changed-format.cjs --base 309db4a` (passed) - `npm run test:delivery-slip && npm run test:rtl-dashboard-pos-common && npm run test:variant-pos-surface` (passed) - `npm run lint` and `npm run docs:check` (passed)
|
@greptileai review |
…ences and update invariants
2ee52b1 to
c386f2f
Compare
|
@greptileai review |
Intent
PR 3 - Financial order-status safeguards (Fixes #1056 and Fixes #1057)
Branch:
codex/order-financial-status-guardsTitle:
fix(orders): guard financial status changesLocked product decisions:
Requirements:
What Changed
PATCH /api/orders/:id/statustransaction so completing orders with unsettled balances or undelivered kitchen items (when policy applies) and cancelling orders that are in progress or hold collected funds require an active owner/manager PIN override with audited safeguard, bill, and balance metadata while leaving payment and bill records untouched.PATCH /api/orders/:id/statustopendingitems so prepared or in-progress items follow void/waste semantics without restoring product, add-on, or recipe stock.OrderCard,OrderDetailPanel, and the orders page to prompt for a manager PIN when cancelling orders with collected payments or completing orders that require override approval, keeping the dialog open on recoverable PIN errors, and updated order-lifecycle and authorization tests and documentation.Risk Assessment
✅ Low: The changes cleanly enforce financial settlement, kitchen delivery, and collected-payment safeguards on PATCH /api/orders/:id/status inside the authoritative SQLite transaction, verify both role (owner/manager) and effective permissions (orders.status.update, orders.item.cancel, payments.take) on the PIN approver, restrict order-cancel stock restoration to pending items so prepared items are not double-restored or silently returned to stock, update the Orders UI cancel flow to prompt for a manager PIN when funds have been collected, and cover all new paths with unit, integration, and E2E tests.
Testing
Built the backend and static frontend, ran targeted Electron/SQLite integration suites (
test:orders-authz,test:cancel-override,test:addon-inventory-lifecycle,test:issue-252,test:recipe-order-lifecycle,authorization-static-audit.test.ts) anddocs:check, executed the Playwright E2E suites (e2e/ops-admin/orders-lifecycle.spec.tsande2e/ops-admin/order-history.spec.ts), and captured live browser screenshots and API/database verification artifacts in~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M; all scenarios passed.npm run test:orders-authzand~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/financial-status-guards-live-verification.jsonnpm run test:orders-authzand~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/financial-status-guards-live-verification.jsonnpx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/ops-admin/orders-lifecycle.spec.ts, `~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/cance…npm run test:cancel-override,npm run test:addon-inventory-lifecycle,npm run test:issue-252, andnpm run test:recipe-order-lifecycleEvidence: Live API and persisted bill state verification for collected-funds cancellation and unpaid completion override
{ "cancelledOrderWithCollectedFunds": { "orderNumber": "ORD-20261015-0001", "billId": 1, "billPaymentStatusAfterCancel": "partial", "billPaidAmountAfterCancel": 20 }, "unpaidCompletionSafeguard": { "orderNumber": "ORD-20261015-0002", "noPinStatus": 400, "noPinBody": { "error": "Manager PIN required to complete unpaid order" }, "badPinStatus": 403, "badPinBody": { "error": "Invalid manager PIN" }, "validPinOverrideStatus": 200, "sameStateRetryStatus": 200, "billAfterCompletionOverride": { "payment_status": "unpaid", "paid_amount": 0, "balance": 64.2 } } }Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:orders-authzand~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/financial-status-guards-live-verification.jsonnpm run test:orders-authzand~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/financial-status-guards-live-verification.jsonnpx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/ops-admin/orders-lifecycle.spec.ts, `~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/cance…npm run test:cancel-override,npm run test:addon-inventory-lifecycle,npm run test:issue-252, andnpm run test:recipe-order-lifecyclenpm run test:orders-authznpm run test:cancel-overridenpm run test:addon-inventory-lifecyclenpm run test:issue-252npm run test:recipe-order-lifecyclenode tests/run-electron-node-test.cjs tests/authorization-static-audit.test.tsnpm run docs:checknpm run build && npm run build:frontendnpx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/ops-admin/orders-lifecycle.spec.ts e2e/ops-admin/order-history.spec.ts --grep-invert='FINDING:|a paid order offers a refund, and issuing it settles against the recorded sale'Live Playwright browser + API verification script capturing~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/cancel-collected-payment-pin-modal.png,~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/cancel-collected-payment-confirmed.png, and~/.no-mistakes/evidence/01M4YM4R1ZR6CVHWQHPZ0F1S0M/financial-status-guards-live-verification.json✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.