Skip to content

fix(reports): exclude cancelled orders and items - #1308

Merged
khaira777 merged 5 commits into
mainfrom
fm/ship-06a30fe0-reports-cancelled-order-filter
Oct 22, 2026
Merged

khaira777 merged 5 commits into
mainfrom
fm/ship-06a30fe0-reports-cancelled-order-filter

Conversation

@khaira777

@khaira777 khaira777 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1298

Intent

Fix the double-verified cancelled-order and voided-item reporting leakage in main/routes/reports.ts from the 06a30fe0 audit (GitHub Issue #1298):

  1. GET /api/reports/summary (main/routes/reports.ts:253-271) queries orders and bills without AND status != 'cancelled' (and paymentMethodBreakdown in main/routes/cash-closures.ts without excludeCancelledOrders).
  2. GET /api/reports/sales (main/routes/reports.ts:507-513, 534-541) queries dailyRows, byOrderType, and byPaymentMethod without excluding cancelled orders.
  3. GET /api/reports/topProducts (main/routes/reports.ts:577-590) queries order_items oi JOIN orders o without AND o.status != 'cancelled' and without AND COALESCE(oi.status, 'active') NOT IN ('cancelled', 'voided', 'void_adjustment', 'refunded').
  4. GET /api/reports/tables (main/routes/reports.ts:699-710) joins orders without AND o.status != 'cancelled'.

What Changed

  • Exclude cancelled orders (status != 'cancelled') from GET /api/reports/summary (order totals, bill counts/totals, collected amounts across bills and refunds, and payment method breakdowns), GET /api/reports/sales (dailySales, byOrderType, and byPaymentMethod), and GET /api/reports/tables (LEFT JOIN orders), via an opt-in excludeCancelledOrders filter in paymentMethodBreakdown (main/routes/reports.ts, main/routes/cash-closures.ts).
  • Exclude cancelled orders and terminal order items (cancelled, voided, void_adjustment, refunded) from product quantity, revenue, and order-count aggregations in GET /api/reports/topProducts (main/routes/reports.ts).
  • Document the reporting exclusion semantics in docs/reference/api.md, add regression coverage in tests/reports-insights.test.ts and frontend/e2e/ops-admin/dashboard-reconciliation.spec.ts, and advance the paused clock after header mount in frontend/e2e/layout-integrity.spec.ts.

@coderabbitai

coderabbitai Bot commented Oct 22, 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

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

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777 khaira777 changed the title fix(main): exclude cancelled orders and non-active items from report endpoints fix(reports): exclude cancelled orders and items Oct 22, 2026
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no new actionable issues were found, and both earlier findings are fixed.

Summary

Excludes cancelled orders from the targeted reports and cancelled, voided, and refunded items from topProducts.

  • Report totals leave cancelled orders out but still show their status.
  • Top-product rankings leave cancelled orders and terminal items out.
  • Test setup reads more clearly and waits for the display header.

Reviews (3) · Last reviewed commit: "no-mistakes(ci): Fixed the failing Playw..." · Reviewed by Greptile

Comment thread main/routes/reports.ts Resolved
Comment thread tests/reports-insights.test.ts Resolved
@khaira777
khaira777 force-pushed the fm/ship-06a30fe0-reports-cancelled-order-filter branch from 7695a3c to 67bb663 Compare October 22, 2026 20:53
@khaira777 khaira777 changed the title fix(reports): exclude cancelled orders and items fix(main): exclude cancelled orders and inactive items from reports Oct 22, 2026
@khaira777 khaira777 changed the title fix(main): exclude cancelled orders and inactive items from reports fix(reports): exclude cancelled orders and items Oct 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

1 similar comment
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

…E2E (Shard 2/4)`, which cascaded to `End-to-End Playwright Tests` and `Required Checks Gate`): - **Invariant:** Whenever `/customer-display` is loaded under a paused Playwright clock (`clock.pauseAt` before `goto`), the test must advance the paused clock across both stages of `CustomerDisplayPage`'s mount effect chain: first `clock.runFor(1)` to fire the token-resolution `setTimeout(..., 0)` (`consumeDisplayTokenFromUrl()` / `setPairedToken(token)`), then wait for React to commit the resolved-token render (`expect(page.locator('header')).toBeVisible()`) so the polling `useEffect` registers `const initial = setTimeout(refresh, 0)`, and finally a second `clock.runFor(1)` to fire `initial`. - **Root cause & fix (`frontend/e2e/layout-integrity.spec.ts`):** Commit `3e1f60c2` added `await budgetPage.clock.pauseAt(new Date(Date.now() + 1000))` before `budgetPage.goto(...)` in `'drains multiple cursor pages, deduplicates overlapping orders, removes completed orders, and clears on follow-up page 401'`, but left only a single `await budgetPage.clock.runFor(1)` after `goto`. Under a paused clock, the first `runFor(1)` only fired the token-resolution timer; the subsequent `setTimeout(refresh, 0)` scheduled after React committed `pairedToken` never fired, hanging `await slowPage1Arrived` until the 30s timeout. Added `await expect(budgetPage.locator('header')).toBeVisible()` and `await budgetPage.clock.runFor(1)` matching the existing paused-clock pattern at lines 2067-2069. - **Verification:** Reproduced the 30s timeout locally before the fix, then verified `npx playwright test --config=playwright.config.ts --project=chromium --retries=0 e2e/layout-integrity.spec.ts -g "customer display wraps full receipt numbers and pages on TV"` (12/12 passed), `npm run lint`, `cd frontend && npx oxfmt --check e2e/layout-integrity.spec.ts`, `npm run docs:check`, and `git diff --check`
@khaira777
khaira777 force-pushed the fm/ship-06a30fe0-reports-cancelled-order-filter branch from e23e8be to 585d7a2 Compare October 22, 2026 21:59
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

1 similar comment
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777 khaira777 changed the title fix(reports): exclude cancelled orders and items fix(reports): exclude cancelled orders and terminal items from reporting aggregates Oct 22, 2026
@khaira777 khaira777 changed the title fix(reports): exclude cancelled orders and terminal items from reporting aggregates fix(reports): exclude cancelled orders and items Oct 22, 2026
@khaira777
khaira777 merged commit 8a3331a into main Oct 22, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/ship-06a30fe0-reports-cancelled-order-filter branch October 22, 2026 22:07
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(reports): exclude cancelled orders and voided items from summary, sales, topProducts, and tables

1 participant