Repository navigation
fix(main): apply document tax rounding across transaction documents - #1282
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
@greptileai review this at apex |
[Medium impact] The changes since the last review appear safe to merge; no new issue needs a separate comment.
|
15e09b8 to
6d2ec9e
Compare
|
@greptileai review this at apex |
Apply document-scope tax rounding across multi-item transactions and charges. - Add calculateDocumentItemTaxes evaluating all items in a single TaxEngine.calculate call - Batch calculateConfiguredChargeTaxes to evaluate active charges in one pass - Call calculateDocumentItemTaxes in calculateTaxPreview, POST /api/orders, and calculateOrderTotals - Reconcile active document items during order/bill mutations - Add comprehensive unit and integration tests for document rounding and mutations - Extend E2E qa-settings-tax spec and capture screenshot Fixes #1274
…Violated Shared baseline test fixtures in `tests/e2e-server.cjs` must preserve the baseline single-product catalog state (`e2e-product` as the sole product in `e2e-category` with consistent inventory ledger state) so that global POS UI assumptions, selector cardinality (`getByTestId('pos-product-card')`), and database export/import inventory integrity hold across all test suites, while spec-specific test fixtures must be dynamically scoped, isolated, and cleanly torn down within their own test lifecycle. #### Root Cause In commit `72d791f5`, two extra products (`e2e-product-rounding-1` and `e2e-product-rounding-2`) with price 100.10, `stock_quantity: 999`, and `track_inventory: 0` were statically added to `seedPosFixture()` in `tests/e2e-server.cjs` under `e2e-category` solely to support document tax rounding assertions in `frontend/e2e/qa-settings-tax.spec.ts`. This polluted the shared E2E test database across every shard: 1. Any test asserting or clicking `page.getByTestId('pos-product-card')` (e.g. `frontend/e2e/checkout-discounts-disabled.spec.ts:556`, `frontend/e2e/diagnostics-checkout-recovery.spec.ts:33`, and multiple suites across Shards 1, 2, and 3) failed with a Playwright strict mode violation because `pos-product-card` resolved to 3 elements instead of 1. 2. `database-export-import.spec.ts` in Shard 1 failed with `Error: Product stock must match the latest inventory movement history` during snapshot restore verification because the two seeded products had nonzero stock with no corresponding inventory movement history. #### Remediation Across All Sites 1. **Shared Fixture Boundary (`tests/e2e-server.cjs`)**: Removed the static insertion of `e2e-product-rounding-1` and `e2e-product-rounding-2` from `seedPosFixture()`. `e2e-category` now contains solely the baseline `e2e-product`. 2. **Spec-Specific Dynamic Fixture Boundary (`frontend/e2e/qa-settings-tax.spec.ts`)**: Updated the test `document tax rounding applies across transaction documents and preserves rounding consistency` to provision its own isolated category (`Tax Rounding Category`) and products dynamically via `POST /api/categories` and `POST /api/products`, reference their returned IDs for tax preview, order creation, and bill generation, and delete them in the `finally` block before restoring the store country setting. ### Verification Run & Results 1. `git diff --check`: Passed with 0 whitespace errors. 2. `npm run lint`: Passed with 0 errors across backend and frontend. 3. `npm run build`: Backend TypeScript build passed. 4. `npm run build:frontend`: Next.js static build and export passed. 5. `npm run docs:check`: Structure, links, index completeness, and process material checks passed. 6. `npm run test:script-coverage`: Passed (253 reachable test scripts, 311 test files covered). 7. `node scripts/run-test.cjs npx tsx tests/integration-tax.test.ts`: Passed (255/255 passed, 0 failed). 8. `node scripts/run-test.cjs npx tsx tests/tax-engine.test.ts`: Passed (16/16 passed, 0 failed). 9. Playwright E2E suites: - `cd frontend && npx playwright test e2e/qa-settings-tax.spec.ts`: Passed (5/5 passed in 15.5s). - `cd frontend && npx playwright test e2e/checkout-discounts-disabled.spec.ts`: Passed (6/6 passed in 41.4s, resolving the strict mode violation). - `cd frontend && npx playwright test e2e/diagnostics-checkout-recovery.spec.ts`: Passed (5/5 passed in 13.8s, resolving the strict mode violation). Checks not run locally: Full multi-shard browser test matrix across all 4 shards (ran focused failing suites locally due to execution time and environment constraints; CI runner executes all shards)
b486f6f to
e6e9728
Compare
|
@greptileai review this at apex |
…ut catalog re-evaluation
|
@greptileai review this at apex |
1 similar comment
|
@greptileai review this at apex |
|
@greptileai review this at apex |
1 similar comment
|
@greptileai review this at apex |
Fixes #1274
Intent
Fix the document tax rounding defect from the FloCafe 3.13.1 release-readiness audit at 3657545 (Issue #1274):
What Changed
calculateDocumentTaxes(), evaluating all order items and configured charges together in a single tax engine pass with stable line identities for tax previews and order creation.recomputeOrderTotals()to reallocate document rounding remainders across existing item snapshots and configured charge snapshots during order mutations without re-evaluating saved items against the active catalog, persisting updated line snapshots, tax amounts, and totals toorder_items.calculateOrderTotals()to filter non-terminal order items and updated architectural documentation for document tax rounding across items, charges, orders, bills, and reports.Risk Assessment
✅ Low: Unified document-scoped tax rounding is correctly implemented across items and charges with persistent snapshots across all transaction lifecycle phases without defects or extraneous abstractions.
Testing
Successfully verified document tax rounding across the live running application: 6 derived end-to-end scenarios passed against real SQLite and Express services with Playwright browser UI rendering, capturing UI screenshots and structured JSON evidence in ~/.no-mistakes/evidence/01M5GFXD0KH5WDGXY5NMQ16AFT, with 273/273 integration tax tests, 16/16 tax engine unit tests, and 5/5 Playwright settings tax tests passing.
Evidence: Scenario 1: Document Tax Preview JSON Evidence
Evidence: Scenario 2: Order Creation and Bill Snapshots JSON Evidence
~/.no-mistakes/evidence/01M5GFXD0KH5WDGXY5NMQ16AFT/scenario-3-mutations.json)~/.no-mistakes/evidence/01M5GFXD0KH5WDGXY5NMQ16AFT/scenario-4-boundary-untaxed.json)Evidence: Scenario 5: Settlement and Tax Components Reporting JSON Evidence
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.
node tests/e2e-server.cjs (live Main API on :3001, KDS on :3002, Server App on :3003)Playwright Chromium headless browser UI interaction on /settings?tab=tax and /orderscd frontend && npx playwright test e2e/qa-settings-tax.spec.tsnpm run test:tax-enginenpm run test:integration-taxEnd-to-end live driver across tax preview, order creation, order mutations, boundary untaxed lines, bill generation, settlement, and tax-components reporting✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.