Repository navigation
fix(reports): use paid_at window for profit - #1377
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Settlement-period profitability main/routes/reports.ts, tests/ingredient-cost-lifecycle.test.ts |
The query attributes profitability to the bill payment period. It prorates split-bill revenue and ingredient cost by allocated quantity. It excludes cancelled, voided, and void-adjustment items, but no longer excludes refunded items or cancelled orders. Tests cover settlement-date attribution and split-bill calculations. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related issues
- Sales reports metrics: This change updates financial-summary profitability calculations, but does not add or expose the revenue, ingredient cost, profit, and margin fields described in the issue.
Merge Risk: 
Minimal · up to 590eb
-
The profitability change is mergeable after normal checks; the reported mismatch reflects the intended settlement-window reporting behavior.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue [
#1371] requires profitability to use the settledbills.paid_atwindow and to match split-bill allocation.main/routes/reports.tsnow filtersbills.paid_at >= ? AND b.paid_at < ?, joinsbill_items, prorates quantity, ex-tax revenue, and known ingredient cost, and excludes void or cancelled item rows.main/services/daily-sales-export.tsuses the same paid-window and allocation rules. The reported regression tests cover cross-midnight settlement and split bills paid in separate windows.
Full details: Out of Scope Changes check
-
Explanation
The reviewed changes are limited to the profitability query in
main/routes/reports.tsand regression tests intests/ingredient-cost-lifecycle.test.ts. The query changes support issue [#1371] by aligning financial-summary profitability with paid bills and daily-sales allocation. The tests verify the required behavior. No unrelated product area or unrelated feature change is shown.
Full details: Description check
-
Explanation
The description explains the problem, intended change, scope, risks, and verification results. It also includes screenshots and regression evidence. It does not use several template headings or explicitly cover compatibility and data safety, cross-cutting surfaces, developer documentation, or the contributor checklist, but the core information is complete.
-
-
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
-
- 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.
Comment @coderabbitai help to get the list of available commands.
|
@coderabbitai review |
✅ Action performed
|
590eb29 to
9d6b2a9
Compare
Fixes #1371
Fixes #1371
Intent
Fix the P2 release-readiness issue from PR #1332 (#1332) interacting with PR #1318 (#1318) at main/routes/reports.ts:677-708: align financial-summary profitability with its settlement window. In main/routes/reports.ts, /financial-summary computes collections using settled bills in the [windowStart, windowEnd) bills.paid_at window, while computePeriodProfitabilitySummary filters order_items by orders.created_at in [windowStart, windowEnd). For an order created before midnight and paid after midnight, /financial-summary reports its profit on the creation day instead of the payment day, disagreeing with buildDailySalesExportDataset in main/services/daily-sales-export.ts:196-251. Align computePeriodProfitabilitySummary with the settled bills.paid_at window and split-bill bill_items allocation.
[P2] Preserve the creation-date aggregate for
/topProducts- #1377, main/routes/reports.ts:719The changed helper also serves
/topProducts, whose product rows still useorders.created_at. Confirmed over HTTP: a cross-midnight sale returns two product units and $11.02 profit alongside an aggregate of zero units/null profit on creation day. Payment day returns an empty product list alongside two aggregate units/$11.02 profit. Keep the new settlement query scoped to/financial-summary, preserving the creation-date aggregate for/topProducts, and cover both responses with a regression test.What Changed
computeSettledProfitabilitySummaryinmain/routes/reports.tsand wire/financial-summaryto compute profitability over the settled[windowStart, windowEnd)bills.paid_atwindow withbill_itemsproportional quantity, revenue, and ingredient cost allocation for split bills.computePeriodProfitabilitySummary(orders.created_atwindow) for/topProductsso its aggregate profitability matches its creation-date product rows.tests/ingredient-cost-lifecycle.test.tscovering cross-midnight order creation versus settlement across/financial-summary,buildDailySalesExportDataset, and/topProducts, plus split bills settled across separate date windows.Risk Assessment
✅ Low: The change scopes settled paid_at and split-bill bill_items profitability aggregation to /financial-summary (matching buildDailySalesExportDataset) while preserving the orders.created_at aggregate for /topProducts, with end-to-end HTTP regression tests covering both endpoints.
Testing
Ran the focused
npm run test:ingredient-costandnpm run test:daily-sales-exportsuites, built the backend and desktop frontend, stood up an isolated live FloCafe server and SQLite database, and drove all four scenarios end-to-end over HTTP and through the rendered Dashboard UI in headless Chromium, capturing full-page Dashboard screenshots for creation day, settlement day, and both split-bill windows along with JSON/CSV reconciliation evidence. All scenarios passed.npm run test:ingredient-costEvidence: Live HTTP API & Daily Sales Export Reconciliation Evidence
{ "scenario1_cross_midnight_creation_day_2026_10_18": { "financialSummaryProfitability": { "total_quantity": 0, "net_revenue": 0, "known_cost_revenue": 0, "known_cost_quantity": 0, "unknown_cost_quantity": 0, "cost_status": "unknown", "ingredient_cost": null, "profit": null, "margin_percent": null }, "topProductsProfitability": { "total_quantity": 2, "net_revenue": 13, "known_cost_revenue": 13, "known_cost_quantity": 2, "unknown_cost_quantity": 0, "cost_status": "known", "ingredient_cost": 1.98, "profit": 11.02, "margin_percent": 84.77 } }, "scenario2_cross_midnight_payment_day_2026_10_19": { "financialSummaryProfitability": { "total_quantity": 2, "net_revenue": 13, "known_cost_revenue": 13, "known_cost_quantity": 2, "unknown_cost_quantity": 0, "cost_status": "known", "ingredient_cost": 1.98, "profit": 11.02, "margin_percent": 84.77 }, "topProductsProfitability": { "total_quantity": 0, "net_revenue": 0, "known_cost_revenue": 0, "known_cost_quantity": 0, "unknown_cost_quantity": 0, "cost_status": "unknown", "ingredient_cost": null, "profit": null, "margin_percent": null } } }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:ingredient-costnpm run test:ingredient-costnpm run test:daily-sales-exportGET /api/reports/financial-summary?start_date=2026-10-18&end_date=2026-10-18(live server + Chromium Dashboard UI)GET /api/reports/topProducts?start_date=2026-10-18&end_date=2026-10-18&limit=10(live server + Chromium Dashboard UI)GET /api/reports/financial-summary?start_date=2026-10-19&end_date=2026-10-19(live server + Chromium Dashboard UI)GET /api/reports/topProducts?start_date=2026-10-19&end_date=2026-10-19&limit=10(live server + Chromium Dashboard UI)GET /api/reports/daily-sales/export?date=2026-10-19&format=csv&part=summary(live server)GET /api/reports/financial-summary?start_date=2026-10-20&end_date=2026-10-20and2026-10-21(split-bill windows live server + Chromium Dashboard UI)GET /api/reports/financial-summary?start_date=2026-10-22&end_date=2026-10-22(adversarial unpaid, cancelled/voided/void_adjustment, unlinked split item, and tax-inclusive split item checks)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.