Skip to content

feat(pos): enforce kitchen delivery before bill settlement - #941

Merged
khaira777 merged 14 commits into
mainfrom
codex/kitchen-delivery-enforcement
Oct 1, 2026
Merged

khaira777 merged 14 commits into
mainfrom
codex/kitchen-delivery-enforcement

Conversation

@khaira777

@khaira777 khaira777 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add an opt-in settlement setting, disabled by default, with printer-only and prepaid bypasses.
  • Block both payment endpoints while kitchen items are pending, preparing, or ready; allow an audited manager PIN override.
  • Add checkout warnings and PIN prompts, settings UI, and translations across all 24 locales.
  • Add focused settlement coverage to the default test suite.

Verification

  • npm test
  • npm run lint
  • npm run build
  • npm run build:frontend
  • npm run i18n:check
  • npm run test:kitchen-delivery-enforcement

Related to #834 (completion remains pending checkout recovery and override fixes).

Summary by CodeRabbit

  • New Features
    • Added an option to require all kitchen items to be marked served before settling postpaid bills. The check is skipped when KDS is disabled.
    • When items are still pending, checkout displays a warning and allows an authorized manager to proceed with a PIN.
  • Bug Fixes
    • Zero-balance bills now settle correctly after kitchen delivery, and tables become available once payment is complete.
  • Tests
    • Added coverage for kitchen-delivery checks, manager overrides, and zero-balance settlement.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

WIP: PR #941 fixes the stale checkout PIN latch and successful-PIN rate counting. It also gates split-check settlement by allocated bill items and keeps undelivered zero-total checks unpaid unless served or covered by the audited manager override. Exact head c3f6dfc has 15 passed, 0 failed, and 1 skipped CI check. Final stacked verification and automated-review follow-up remain in progress. Please do not merge yet; readiness will be confirmed here.

@khaira777

khaira777 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Final verification complete for PR #941 at head fbcba67. Current-main sync is included, migration v97 follows v96, and the branch covers the kitchen-delivery settlement gate, PIN rate counting, split bills, zero-total/zero-tender recovery, and #939/#940 integrations. Local validation passed: npm test; lint and lint budget; backend/frontend builds; i18n/docs; kitchen-delivery, zero-balance (106/106), cash sessions (134/134), payment integration (33/33 plus issue-689 11/11), authorization, migration registry (296/296), upgrade path, focused settings browser (31/31), and full browser E2E (112/112). Exact-head hosted checks: 16 passed, 0 failed, 1 documentation check skipped by path filtering. Greptile reports no findings; CodeRabbit found no actionable comments; all six review threads are resolved. Issue #834 remains open and is referenced as Related to #834, not by a closing keyword.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Adds kitchen delivery enforcement to payment settlement flow.

The PR appears safe to merge based on the reviewed changes and resolved prior threads.

Summary

The PR adds an opt-in kitchen-delivery check before postpaid settlement, with a manager PIN override, checkout prompts, settings, translations, and regression coverage.

  • Zero-balance bills can be settled through the payment modal after delivery.
  • The changes since the previous review correct browser-test assertions for local network pairing cards.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Payment request] --> B{Delivery check enabled?}
  B -- No --> E[Settle bill]
  B -- Yes --> C{Bill items delivered?}
  C -- Yes --> E
  C -- No --> D{Valid manager PIN?}
  D -- Yes --> F[Audit override] --> E
  D -- No --> G[Block settlement]
Loading

Reviews (5) · Last reviewed commit: "test(settings): assert local pairing car..."

Comment thread main/routes/bills.ts Resolved
Comment thread main/routes/bills.ts Resolved
Comment thread main/routes/reports.ts Resolved
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

Comment thread main/routes/bills.ts Resolved
Comment thread frontend/src/lib/whatsapp-share.ts Resolved
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 3807d178-af02-4c27-8b2b-ec69ee18f7a7

📥 Commits

Reviewing files that changed from the base of the PR and between d7f538f and fbcba67.

📒 Files selected for processing (1)
  • frontend/e2e/settings-request-budget.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Walkthrough

The change adds an optional kitchen-delivery requirement for postpaid bill settlement. It blocks settlement while eligible kitchen items remain undelivered, supports manager-PIN overrides, adds POS settings and payment prompts, and includes database migration and regression coverage.

Changes

Kitchen delivery settlement

Layer / File(s) Summary
Settlement policy and payment enforcement
main/db.ts, main/routes/settings.ts, main/routes/bills.ts
The new setting defaults to disabled and can be updated through the settings route. When enforcement applies, pending, preparing, or ready items block settlement unless an active owner or manager PIN is valid. Override attempts are rate-limited, successful overrides are audited, and payment errors include delivery details.
POS setting and checkout flow
frontend/src/app/(dashboard)/settings/page.tsx, frontend/src/app/(dashboard)/pos/page.tsx, frontend/src/components/pos/PaymentModal.tsx, frontend/src/components/pos/TableCheckoutModal.tsx, frontend/src/lib/i18n/messages/*.json
The KDS settings page loads and saves the delivery requirement. The payment modal displays undelivered-item details and accepts a manager PIN. Checkout carries the optional PIN into the payment modal, and locale files add related messages.
Settlement regression coverage
tests/kitchen-delivery-enforcement.test.ts, tests/issue-zero-balance-settlement.test.ts, tests/cash-sessions.test.ts, tests/upgrade-path.test.ts, frontend/e2e/kitchen-delivery-payment-retry.spec.ts, package.json
Tests cover enforcement conditions, PIN overrides and throttling, split and zero-balance settlement, payment details, migration defaults, and POS retry flows. The main test script now runs the kitchen-enforcement suite.

Local network address checks

Layer / File(s) Summary
Shared local address card assertion
frontend/e2e/settings-request-budget.spec.ts
The test checks the local address card’s link, label, and local-network hint for POS, Kitchen Display, and Tableside Ordering.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant POS
  participant BillsRoute
  participant KitchenDeliveryCheck
  participant Database
  POS->>BillsRoute: Submit payment with optional manager PIN
  BillsRoute->>KitchenDeliveryCheck: Check settlement eligibility
  KitchenDeliveryCheck->>Database: Read settings, item statuses, and manager PIN
  Database-->>KitchenDeliveryCheck: Return setting and item and manager data
  KitchenDeliveryCheck-->>BillsRoute: Return block or valid override
  BillsRoute->>Database: Record override audit and settle bill
  BillsRoute-->>POS: Return payment result or kitchen error details
Loading

Merge Risk: ⚪ Minimal · up to fbcba

The shared local-address checks match all three settings views. No actionable merge-blocking risk is established; merge readiness remains subject to normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to fbcba

The delivery check is enforced on the server and defaults off. The main concern is that a manager’s override authority depends on role and PIN rather than configured payment permissions. Payment execution remains permission-protected, but delegated approval policy and recovery behavior need clarification.

Retained concerns

  • Medium · security · inferred: The new exception grants approval authority to any active owner/manager with a valid PIN without evaluating that approver’s configured payment permission. A caller with payments.take can therefore obtain an exception using a manager whose payment authority has been revoked. Existing discount and cancellation approvals also require an action-specific permission. Whether this separate role-based approval authority is intentional remains unresolved.
Security review details

Security Blast Radius

  • inferred — The identified approval-policy concern reaches bills available to a payments.take caller when enforcement is enabled, billing is postpaid, and KDS is active. Exercising it requires a valid active owner/manager PIN. The inspected path can affect payment and loyalty records, order completion, and table availability in the database used by the payment API; cross-tenant isolation was not established.

Security Findings and Attack Paths

  • inferred — A payment-authorized caller can submit an undelivered bill with an active manager’s valid PIN. The new helper accepts the manager by role without consulting effective payment permission, then allows the settlement sink. This is a potential revocation-policy mismatch, not evidence that unauthenticated callers can settle bills or that the PR expands payment execution beyond its existing permission boundary.

Trust Boundaries and Controls

  • observed — The browser does not decide kitchen eligibility: the server reads item ownership, positive bill allocation, and status independently. The cashier remains the authenticated payment actor, while a separately PIN-authenticated manager supplies exception authority. Configuration writes retain their settings.manage boundary.

Resilience and Maintainability Implications

  • observed — A successful exception can use the existing transition that completes a fully paid order and releases its table without changing kitchen-item statuses. Base/head comparison shows that transition already existed before this PR, so outstanding kitchen work after settlement is not treated as a newly introduced defect. Its intended recovery ownership remains unresolved.

Hardening Proposals

  • proposed — Define delegated kitchen-exception authority explicitly: either require the approver’s effective settlement permission or introduce a separately revocable exception-approval permission. This would distinguish intentional role-based delegation from permission-control drift.
  • proposed — Make the PIN’s approval lifetime explicit across committed partial payments and retries. The modal currently clears the prompt after success but retains the PIN; clearing it after a committed response would avoid silently carrying approval credentials into a subsequent payment request.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a useful summary and verification commands, but it omits most required template sections, including scope, compatibility and data safety, screenshots, cross-cutting surfaces, … Complete the repository template. Add the Related work, Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Developer documentation, and Contributor checklist sections. Document verification results, migration impact, u…
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: enforcing kitchen delivery before bill settlement.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes a useful summary and verification commands, but it omits most required template sections, including scope, compatibility and data safety, screenshots, cross-cutting surfaces, developer documentation, and the contributor checklist. Related work is also not presented under the required heading.

Resolution

Complete the repository template. Add the Related work, Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Developer documentation, and Contributor checklist sections. Document verification results, migration impact, user-visible behavior, affected surfaces, and checklist selections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

frontend/e2e/settings-request-budget.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@khaira777
khaira777 merged commit 9a09150 into main Oct 1, 2026
17 checks passed
@khaira777
khaira777 deleted the codex/kitchen-delivery-enforcement branch October 1, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant