Skip to content

fix(orders): fetch bill on filtered tab print - #1650

Merged
khaira777 merged 3 commits into
mainfrom
fm/flocafe-fix-orders-print-tab
Nov 27, 2026
Merged

khaira777 merged 3 commits into
mainfrom
fm/flocafe-fix-orders-print-tab

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Fix the confirmed non-product bug tracked in #1639 where OrdersPage.handlePrint prematurely fails with "Bill not found" when printing an order that has left the currently filtered Orders tab instead of fetching GET /api/bills/:id. Ship a minimal fix with regression tests via a PR that closes #1639.

What Changed

  • Removed the upfront candidateOrders / matchedBill guard in OrdersPage.handlePrint (frontend/src/app/(dashboard)/orders/page.tsx) so printing always fetches GET /api/bills/:id even when the order is no longer in the active filtered tab.
  • Handled 404 responses and empty payloads from GET /api/bills/:id (when no fallbackBill is provided) by showing the billNotFound toast and returning early instead of throwing, while preserving non-404 error propagation.
  • Added regression tests in tests/orders-search.test.ts covering out-of-tab bill printing, 404 and null-bill responses, and non-404 fetch errors with and without an in-tab cached bill.

Closes #1639

Risk Assessment

✅ Low: Minimal, well-bounded fix in OrdersPage.handlePrint that removes the premature local-tab guard, surfaces billNotFound on 404 or missing bill payloads without falling back to cached list bills, and adds regression tests covering out-of-tab printing and error handling.

Testing

Built the backend and desktop frontend, ran npm run test:orders-search (all unit, API, and performance tests passed including the new handlePrint regression test), and drove three live Chromium scenarios against the real isolated FloCafe server (tests/e2e-server.cjs) covering out-of-tab receipt printing, 404 bill-not-found handling, and in-tab 500 error handling without stale fallback, capturing four PNG screenshots as evidence; all scenarios passed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Local FloCafe desktop web app: printing a bill whose order left the Unpaid Orders tab fetches GET /api/bills/:id and prints the receipt instead of failing with Bill not found ✅ pass live scenario1-out-of-tab-print-success.png, scenario1-receipt-popup.png, and live Playwright run against tests/e2e-server.cjs (GET /api/bills/1 -> 200, POST /api/bills/1/print -> 200)
Local FloCafe desktop web app (adversarial): confirming print when GET /api/bills/:id returns 404 displays Bill not found and closes the reserved print window ✅ pass live scenario2-404-bill-not-found.png and live Playwright run against tests/e2e-server.cjs (GET /api/bills/2 intercepted with HTTP 404, 0 open popups remaining)
Local FloCafe desktop web app (adversarial): confirming print for an in-tab order when GET /api/bills/:id returns 500 surfaces Failed to print receipt without falling back to stale cached list data ✅ pass live scenario3-in-tab-500-no-stale-fallback.png and live Playwright run against tests/e2e-server.cjs (GET /api/bills/2 intercepted with HTTP 500, 0 POST /api/bills/2/print calls, 0 open popups remaining)

Scenario 1: Orders Unpaid tab shows print success toast after paid order left the tab

Scenario 1: Rendered receipt popup printed for out-of-tab order #ORD-20261128-0001

Scenario 2: Orders page displays Bill not found error toast on 404 from GET /api/bills/:id

Scenario 3: Orders page displays Failed to print receipt (DB busy) on 500 without falling back to cached in-tab bill

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ frontend/src/app/(dashboard)/orders/page.tsx:1513 - Unrequired matchedBill fallback introduced in handlePrint (also at frontend/src/app/(dashboard)/orders/page.tsx:1497 and frontend/src/app/(dashboard)/orders/page.tsx:1507). No requirement in the user intent asks to fall back to the cached bill from the local orders list—the intent is specifically to fetch GET /api/bills/:id when an order has left the filtered tab (where matchedBill is undefined anyway). This fallback also introduces a regression for orders still in the current tab when options?.fallbackBill is not passed: previously, a non-404 GET /bills/:id failure (e.g., 500, 403, 401, or network error) threw and surfaced orders.printReceiptFailed, whereas now handlePrint silently swallows the error and prints potentially stale matchedBill data from the list snapshot (and similarly prints matchedBill if GET /bills/:id returns 200 with a missing bill payload). Smallest honest remedy: remove matchedBill at line 1497 and its fallback uses at lines 1507 and 1513, keeping only options?.fallbackBill.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Local FloCafe desktop web app: printing a bill whose order left the Unpaid Orders tab fetches GET /api/bills/:id and prints the receipt instead of failing with Bill not found ✅ pass live scenario1-out-of-tab-print-success.png, scenario1-receipt-popup.png, and live Playwright run against tests/e2e-server.cjs (GET /api/bills/1 -> 200, POST /api/bills/1/print -> 200)
Local FloCafe desktop web app (adversarial): confirming print when GET /api/bills/:id returns 404 displays Bill not found and closes the reserved print window ✅ pass live scenario2-404-bill-not-found.png and live Playwright run against tests/e2e-server.cjs (GET /api/bills/2 intercepted with HTTP 404, 0 open popups remaining)
Local FloCafe desktop web app (adversarial): confirming print for an in-tab order when GET /api/bills/:id returns 500 surfaces Failed to print receipt without falling back to stale cached list data ✅ pass live scenario3-in-tab-500-no-stale-fallback.png and live Playwright run against tests/e2e-server.cjs (GET /api/bills/2 intercepted with HTTP 500, 0 POST /api/bills/2/print calls, 0 open popups remaining)
  • npm run build
  • npm run build:frontend
  • npm run test:orders-search
  • Playwright Chromium live E2E verification against tests/e2e-server.cjs (scenarios 1-3 on /orders Unpaid tab with cards layout)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Issues

Closes #1639

@coderabbitai

coderabbitai Bot commented Nov 27, 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-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix receipt printing for orders outside the active tab

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Fetch bills before printing, even when their orders have left the filtered tab.
• Show “Bill not found” for missing bills while preserving other fetch errors.
• Add regression coverage for out-of-tab printing, missing bills, and stale-cache avoidance.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed path begins at the Orders-page print confirmation, retrieves the bill, invokes the printer, and records print history for the same receipt-printing outcome.
  • The API retrieval and printer call are implementation hops of this bounded integration, not independent capabilities.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, printing was blocked when the bill was absent from the locally loaded order list, and retrieval failures were generally propagated unless a fallback bill existed.
  • After, the handler retrieves the bill even when the active filtered list lacks the order, distinguishes a no-fallback 404 from other failures, preserves fallback behavior, and lets the existing finally block close an unused reserved print window.
  • New correctness condition: the bill-fetch result, fallback presence, HTTP status, tenant continuity, and reserved-window ownership must lead to the correct user result without printing an absent or stale bill.
  • The underlying printer and API helpers are reused; their existence does not add complexity by itself.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the changed retrieval or error branch regresses, the affected end-to-end capability is the current receipt-print attempt.
  • A user may be unable to print that receipt, but the behavior does not itself alter bill state or create a financial transaction.
  • The existing printer-error path reports failure, while a successful later retry or reprint can restore the capability.
  • Retrying the print or using the existing reprint flow can recover a failed receipt attempt.
  • Reverting the code restores the prior control flow; no persistent-state repair or external compensation is supported as necessary by this change.
Assessed commit 66bc06e
Diagram

sequenceDiagram
    actor Staff
    participant Orders as Orders Page
    participant API as Bills API
    participant Printer
    participant Toast
    Staff->>Orders: Confirm print
    Orders->>API: GET bill by ID
    alt Bill returned
        API-->>Orders: Current bill
        Orders->>Printer: Print receipt
        Orders->>API: Record print
    else 404 or empty bill
        API-->>Orders: Bill unavailable
        Orders->>Toast: Bill not found
    else Other fetch error
        API-->>Orders: Fetch failure
        Orders->>Toast: Print failed
    end
Loading
High-Level Assessment

Keep the targeted API-first fix. Using the filtered list as a prerequisite or falling back to its cached bill would reintroduce the missing-order failure or risk printing stale data; the existing explicit fallback remains available to its intended caller.

Files changed (2) +594 / -9

Bug fix (1) +10 / -9
page.tsxFetch bills before deciding whether a receipt can print +10/-9

Fetch bills before deciding whether a receipt can print

• Removes the active-list bill guard so out-of-tab orders can print from the fetched bill. Treats 404 and empty bill responses as bill-not-found cases, while retaining non-404 error handling and the explicit fallback bill.

frontend/src/app/(dashboard)/orders/page.tsx

Tests (1) +584 / -0
orders-search.test.tsCover out-of-tab printing and bill-fetch failures +584/-0

Cover out-of-tab printing and bill-fetch failures

• Adds a mocked OrdersPage regression test for printing a bill absent from the active list. It also checks 404 and null-bill feedback, non-404 failures, reserved-window cleanup, and avoidance of stale in-tab bills.

tests/orders-search.test.ts

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777 khaira777 changed the title fix(orders): fetch bill from API when printing outside active tab fix(orders): fetch bill on filtered tab print Nov 27, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable issues were found.

Summary

OrdersPage.handlePrint now fetches the bill even when its order has left the filtered tab.

  • Orders printing fetches bills even when their orders leave the active tab.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Confirm print] --> B[Fetch bill by ID]
  B --> C{Bill available?}
  C -->|Yes| D[Print fetched bill]
  C -->|Explicit fallback| E[Print fallback bill]
  C -->|404 or empty bill| F[Show bill not found]
  B -->|Other error without fallback| G[Show receipt error]
  F --> H[Close unused window and clear printing state]
  G --> H
Loading

Reviews (1) · Last reviewed commit: "no-mistakes(review): Remove matchedBill ..." · Reviewed by Greptile

@khaira777
khaira777 merged commit b8a09db into main Nov 27, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-fix-orders-print-tab branch November 27, 2026 23:20
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.

fix(orders): fetch bill from API when printing outside active tab

1 participant