Skip to content

fix(orders): guard refunded releases and scheduled listings - #1414

Merged
khaira777 merged 1 commit into
mainfrom
codex/audit-scheduled-release
Oct 31, 2026
Merged

khaira777 merged 1 commit into
mainfrom
codex/audit-scheduled-release

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Summary

Addresses release audit findings F-1 and F-2 for scheduled and deferred orders:

  1. F-1: Prevents releasing fully refunded scheduled orders, applying an explicit blocked status with reason refunded and recording audit log entries.
  2. F-2: Excludes unscheduled deferred orders (scheduled_for IS NOT NULL) from the /api/orders/scheduled drawer queue and count.

Changes

  • main/services/scheduled-orders.ts: Add gate checking if all bills are refunded (billCounts.total > 0 && billCounts.total === billCounts.refunded). Transition order to release_status = 'blocked', release_blocked_reason = 'refunded', and record release_blocked audit event.
  • main/routes/orders.ts: In /api/orders/scheduled, filter scheduled_for IS NOT NULL.
  • ScheduledOrdersDrawer.tsx: Localize release-blocked reasons including refunded, and provide status feedback.
  • PaymentQueueDrawer.tsx: Ensure payment queue drawers handle deferred payments cleanly.
  • tests/issue-360-scheduled-orders.test.ts & tests/multi-counter-ordering.test.ts: Add regression tests for refund hold and deferred order filtering.
  • Documentation: Document refunded scheduled hold and drawer filtering rules in docs/architecture/order-lifecycle.md.

Stack

Verification

  • npm run test:scheduled-orders: Passed (364/364)
  • npm run test:multi-counter-ordering: Passed (252/252)

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@qodo-code-review

qodo-code-review Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Block fully refunded releases and filter scheduled orders

🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Block and audit kitchen release when every bill on an order is refunded.
• Exclude undated deferred orders from scheduled queue pages and counts; explain refund holds in POS
 drawers.
• Preserve refund approver selections across time changes and cover release, queue, and modal
 behavior with tests.
Diagram

graph TD
  Modal["Refund approval"] --> Bills["Bill state"] --> Refunded{"All bills refunded?"}
  Release["Manual or sweep"] --> Refunded
  Refunded -->|Yes| Hold["Block and audit"] --> Drawers["POS drawers"]
  Refunded -->|No, existing gates pass| Kitchen["Kitchen release"]
  Queue["Scheduled API"] -->|Dated orders only| Drawers
Loading
High-Level Assessment

Keep the refund check in the shared transactional release service so manual retries and automatic sweeps enforce the same rule. Route-specific checks would duplicate policy and leave more room for inconsistent release behavior; filtering both the scheduled query and its count is likewise appropriate.

Files changed (14) +760 / -68

Bug fix (5) +128 / -24
RefundModal.tsxKeep refund approval input stable and gated +65/-20

Keep refund approval input stable and gated

• Stops time-tier changes from refetching approvers and resetting a valid selection and PIN. Disables PIN entry and submission until approvers are ready, and clears the PIN when the selected approver becomes ineligible.

frontend/src/components/orders/RefundModal.tsx

PaymentQueueDrawer.tsxExplain refunded payment-queue holds +10/-2

Explain refunded payment-queue holds

• Replaces the raw 'refunded' reason with localized cancellation guidance in blocked-order cards and failed retry notifications.

frontend/src/components/pos/PaymentQueueDrawer.tsx

ScheduledOrdersDrawer.tsxExplain refunded scheduled-order holds +8/-2

Explain refunded scheduled-order holds

• Shows localized cancellation guidance instead of a raw 'refunded' reason on scheduled-order cards and failed release notifications.

frontend/src/components/pos/ScheduledOrdersDrawer.tsx

orders.tsExclude undated orders from the scheduled queue +2/-0

Exclude undated orders from the scheduled queue

• Applies 'scheduled_for IS NOT NULL' to both scheduled-order counts and paginated results, keeping unscheduled deferred tickets out of the drawer.

main/routes/orders.ts

scheduled-orders.tsHold release when every bill is refunded +43/-0

Hold release when every bill is refunded

• The shared release transaction blocks orders with at least one bill when all bills are refunded, persists reason 'refunded', and audits the transition. Repeated attempts return the hold without duplicating its audit entry.

main/services/scheduled-orders.ts

Tests (5) +620 / -38
multi-counter-ordering.spec.tsCover refunded holds in the payment queue +28/-0

Cover refunded holds in the payment queue

• Mocks a refunded release block to verify the payment queue displays cancellation guidance in the card and retry feedback, then restores the original stock-hold view.

frontend/e2e/multi-counter-ordering.spec.ts

scheduled-orders.spec.tsExercise refund holds and approver-state transitions +181/-35

Exercise refund holds and approver-state transitions

• Tests manual release feedback for a fully refunded order and refund-modal behavior during delayed, failed, and empty approver loads and changing time-based eligibility. Uses disposable approver fixtures instead of modifying a shared manager.

frontend/e2e/scheduled-orders.spec.ts

issue-360-scheduled-orders.test.tsVerify fully refunded scheduled releases stay blocked +143/-1

Verify fully refunded scheduled releases stay blocked

• Covers sweep and manual retry responses, a single audit entry, and preservation of order values, stock, and KOT output. The refund fixture includes a tracked variant and add-on.

tests/issue-360-scheduled-orders.test.ts

multi-counter-ordering.test.tsCover deferred queue filtering and refund-release gates +257/-2

Cover deferred queue filtering and refund-release gates

• Checks scheduled counts, pagination, and exclusion of undated deferred tickets. Also verifies fully refunded deferred orders remain blocked without stock or KDS effects, while mixed split-bill states retain the payment gate.

tests/multi-counter-ordering.test.ts

reports-export.test.tsAllow bounded timestamp drift in export comparison +11/-0

Allow bounded timestamp drift in export comparison

• Compares HTML and XLSX shift-report period-end timestamps within five seconds instead of requiring exact text equality.

tests/reports-export.test.ts

Documentation (2) +10 / -4
order-lifecycle.mdDocument refund holds and approver behavior +8/-2

Document refund holds and approver behavior

• Describes cancellation as the recovery path for fully refunded scheduled orders. Also documents how the refund modal retains eligible approval input and reacts when eligibility changes.

docs/architecture/order-lifecycle.md

api.mdClarify scheduled listing and release responses +2/-2

Clarify scheduled listing and release responses

• Documents the non-null schedule requirement for the scheduled queue and the refunded-bill release hold, including its response and recovery path.

docs/reference/api.md

Other (2) +2 / -2
ci.ymlRun pull-request CI for codex branches +1/-1

Run pull-request CI for codex branches

• Adds 'codex/*' to the workflow's pull-request target branches.

.github/workflows/ci.yml

package.jsonRun server-app browser tests separately +1/-1

Run server-app browser tests separately

• Splits the default browser E2E command into the main suite and a separate 'server-app-ordering.spec.ts' invocation, retaining the existing test exclusions.

package.json

@qodo-code-review

qodo-code-review Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Refunded pay-at-counter tickets lose their cancel button 🐞 Bug ≡ Correctness
Description
Adding scheduled_for IS NOT NULL to /api/orders/scheduled removes on_payment tickets that have
no scheduled time from the Scheduled drawer, and that drawer is the only POS drawer with a cancel
action. When such a ticket is blocked with reason refunded, PaymentQueueDrawer shows the new
"Refunded. Cancel." message and a retry-release button but has no cancel control, so cashiers have
to leave POS and cancel from the Orders screen.
Code

main/routes/orders.ts[R1485-1488]

      let sql = `SELECT * FROM orders
                 WHERE release_status IN ('scheduled', 'blocked')
+                   AND scheduled_for IS NOT NULL
                   AND status NOT IN ('cancelled', 'completed')`;
Relevance

●●● Strong

Refunded deferred orders need an in-POS cancellation path; prior refunded-order safeguards were
accepted.

PR-#810

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The awaiting-payment queue lists blocked on_payment orders, but it only offers retry, refund, pay
and print. Before this PR, those orders also appeared in the Scheduled drawer, which has a cancel
button. The new filter removes them from that drawer, while the new UI text tells staff to cancel.

main/routes/orders.ts[1584-1586]
frontend/src/components/pos/PaymentQueueDrawer.tsx[319-416]
frontend/src/components/pos/ScheduledOrdersDrawer.tsx[647-668]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Refund-blocked `on_payment` tickets with no `scheduled_for` now appear only in PaymentQueueDrawer. That drawer tells staff to cancel but has no cancel action.

## Fix Focus Areas
- frontend/src/components/pos/PaymentQueueDrawer.tsx[319-416]
- main/routes/orders.ts[1474-1488]

## Recommended Fix
Add a cancel action to PaymentQueueDrawer for blocked orders, at least when `release_blocked_reason === 'refunded'`, gated on `orders.status.update` and reusing the PATCH /:id/status cancel flow from ScheduledOrdersDrawer. As an alternative, keep `release_blocked_reason = 'refunded'` orders in the scheduled query even when `scheduled_for` is null.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #1413
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: 🧠 Deep: Broad refund, release, queue, UI, and test logic creates dense independent risk.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777
khaira777 force-pushed the codex/audit-refund-approval branch from b49d891 to 6f3c647 Compare October 31, 2026 21:26
@khaira777
khaira777 force-pushed the codex/audit-scheduled-release branch from be88b46 to 631ee15 Compare October 31, 2026 21:26
@khaira777
khaira777 deleted the branch codex/audit-refund-approval October 31, 2026 22:43
@khaira777 khaira777 closed this Oct 31, 2026
@khaira777 khaira777 reopened this Oct 31, 2026
@khaira777
khaira777 changed the base branch from codex/audit-refund-approval to main October 31, 2026 22:43
@khaira777
khaira777 force-pushed the codex/audit-scheduled-release branch from 631ee15 to 7129ecf Compare October 31, 2026 22:43
Comment thread main/routes/orders.ts Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 631ee15

@khaira777
khaira777 merged commit 4cfe0c2 into main Oct 31, 2026
23 checks passed
@khaira777
khaira777 deleted the codex/audit-scheduled-release branch October 31, 2026 22:55
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