Repository navigation
fix(tax): round document tax after order discounts - #1293
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 |
[High impact] The changes reach tax amounts shown in order previews, saved orders, bills, and tax reports. Fix the line-scoped snapshot precision mismatch before merging, because receipts and reports can overstate saved tax. Findings
|
b4963e1 to
211ba44
Compare
|
@greptileai review this at apex |
211ba44 to
d2d888d
Compare
|
@greptileai review this at apex |
d2d888d to
122dd27
Compare
|
@greptileai review this at apex |
Fixes #1288 Apply the exact Decimal order-discount ratio to raw item tax components before running document-scope largest_remainder rounding across combined discounted-item and unchanged-charge components in recomputeOrderTotals and calculateTaxPreview, while persisting order_items with their un-order-discounted document tax allocation so subsequent discount edits never compound.
…l item projection
122dd27 to
b2d716e
Compare
|
@greptileai review this at apex |
|
@greptileai review this at apex |
Fixes #1288
Intent
Fix issue #1288: apply order discounts before document-scope tax rounding allocation, preserve Decimal discount ratio for line-scoped snapshots, and normalize override unit prices in preview and cart
What Changed
allocateDocumentTaxRounding,rollupOrderTaxes, and 40-digitDecimalcomputeDiscountTaxRatioinmain/services/tax.tssorecomputeOrderTotalsandcalculateTaxPreviewscale raw unrounded document-scope item tax components (amount + roundingRemainder) by the order-discount ratio before runninglargest_remainderdocument rounding across combined item and charge tax components, while persisting un-order-discounted document tax allocations onorder_items.Decimaldiscount ratios throughscaleTaxBreakdowns,scaleTaxSnapshots,combineItemAndChargeTaxes, andprojectOrderItemsalongsideDecimalsubtotal/total accumulation, and updatedprojectOrderItemsinmain/routes/bills.tsto project discounted document line allocations fromorder.tax_snapshotwith a fallback toallocateDocumentTaxRounding.normalizeOverridePriceacross backend override parsing (main/services/item-price-override.ts), tax preview quoting (main/services/tax.ts,frontend/src/hooks/use-tax-preview.ts), and frontend cart pricing, identity, and order payload helpers (frontend/src/lib/cart-price.ts,frontend/src/lib/cart-identity.ts,frontend/src/lib/cart-order-item.ts,frontend/src/store/cart.ts), with matching architecture docs and regression tests.Risk Assessment
✅ Low: The changes cleanly address issue #1288 across backend tax calculation, order total recomputation, bill item projection, and frontend/backend price-override normalization. Document-scoped tax rounding now scales raw item tax components by the high-precision Decimal discount ratio before largest-remainder allocation while keeping persisted item rows un-order-discounted and charges unscaled; line-scoped snapshot scaling preserves the Decimal ratio and tie-break order; bill item projection reuses saved order snapshot entries; and override unit prices are normalized consistently using half-up decimal rounding in preview, cart, and order creation. All 16 changed files were inspected and verified with no defects found.
Testing
Ran the six targeted test suites (
test:cart-price-override,test:item-price-override,test:tax-engine,test:order-totals-recompute,test:tax-components, andtest:integration-tax), then stood up the compiled FloCafe server and static Next.js frontend against an isolated SQLite database and drove all four scenarios live through headless Chromium and the HTTP API, capturing POS checkout and cart screenshots plus a structured JSON evidence transcript; all checks and scenarios passed.npm run test:tax-engine;npm run test:integration-tax;npm run test:tax-componentsnpm run test:order-totals-recompute;npm run test:integration-taxEvidence: Live validation evidence JSON (API, DB, and browser scenario outputs)
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:tax-engine;npm run test:integration-tax;npm run test:tax-componentsnpm run test:order-totals-recompute;npm run test:integration-taxnpm run test:cart-price-overridenpm run test:item-price-overridenpm run test:tax-enginenpm run test:order-totals-recomputenpm run test:tax-componentsnpm run test:integration-taxnpm run build && npm run build:frontend(for live server + browser execution)Live Chromium POS + Express API + SQLite scenario run capturing~/.no-mistakes/evidence/01M5JRZBTDMEPQH86Q1AHM45HY/pos-payment-modal-discount-tax-rounding.png,~/.no-mistakes/evidence/01M5JRZBTDMEPQH86Q1AHM45HY/pos-cart-price-override-normalized.png, and~/.no-mistakes/evidence/01M5JRZBTDMEPQH86Q1AHM45HY/live-validation-evidence.json✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.