Repository navigation
fix: preserve currency precision and saved tax-pack version on customer change - #1324
Merged
Merged
Conversation
… version on customer change
Contributor
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Verify and fix the currency-precision and saved-tax-rule regressions from the merged-PR release audit, plus check 3-decimal currencies (such as KWD, BHD, OMR, JOD, TND) and 0-decimal / Japan (JP / JPY / community-japan.json) calculations so everything is accurate:
frontend/src/lib/cart-price.ts: Cart price overrides (clampCartPriceOverride) and cart subtotal helpers (frontend/src/store/cart.ts,frontend/src/hooks/use-tax-preview.ts,frontend/src/lib/cart-order-item.ts) currently round to 2 decimal places (Math.round(n * 100) / 100), which truncates 3-decimal currencies like KWD (1.234becomes1.23, and0.004rounds to0and becomes a free line) and allows fractional overrides on 0-decimal currencies like JPY.main/routes/orders.ts: Attaching or changing a customer viaPATCH /api/orders/:id/customerafter a country tax-pack version update (1.0.0to1.0.1) currently recalculatesorder_itemsagainst the newly active pack version instead of the order item's savedpackVersion, changing an unpaid bill's tax from 50 to 100 and overwritingtax_snapshot.packVersionfrom"1.0.0"to"1.0.1".KWD,BHD,OMR,JOD,TND) and 0-decimal / Japan (JP/JPY/community-japan.json) tax and payable-rounding calculations honor the currency's fraction digits (resolvePayableIncrementinmain/services/tax-engine.tswhenpack.currency === 'XXX'andgetCurrencyFractionDigits(currency) !== configuredDecimals).What Changed
frontend/src/lib/cart-price.ts(resolveActiveCurrencyDecimals,roundMoney,clampCartPriceOverride,normalizeOverridePrice, andcartLineUnitPrice) to round cart prices and overrides using the active currency's fraction digits (supporting 0-decimal and 3-decimal currencies instead of fixed 2-decimal rounding).PATCH /api/orders/:id/customerinmain/routes/orders.tsandmain/services/tax.tsto skip item tax re-evaluation when customer B2B/state tax context is unchanged, resolve each item's savedpackIdandpackVersionviagetCountryPackByVersion, and accept snake_casetax_registration_numberon customer records.resolvePayableIncrementinmain/services/tax-engine.tsto use the configured currency's minor-unit increment whenever acurrency: 'XXX'pack's increment decimals differ from the currency's fraction digits, fell back totaxRounding.decimalPlacesinallocateDocumentTaxRounding, and updated architecture docs and regression tests.Risk Assessment
✅ Low: The changes are well-bounded and directly address currency-precision rounding in cart price overrides/subtotals, historical tax-pack version preservation on customer updates, and 0-/3-decimal payable increment resolution with end-to-end and unit test coverage.
Testing
Ran the targeted automated suites (test:cart-price-override, test:order-totals-recompute, test:tax-engine, test:currency, test:item-price-override, test:integration-tax, and test:community-tax-packs), built the backend and static frontend, and stood up an isolated Express + SQLite POS instance driven by headless Chromium and live HTTP requests. Verified and captured screenshots and API/database transcripts for KWD 3-decimal POS cart price overrides (1.234 KWD and the 0.004 KWD boundary), JPY 0-decimal fractional override rounding (1080.7 -> 1081 JPY) and Japan community tax pack calculations (1,100 JPY dine-in + 1,080 JPY takeaway = 2,180 JPY with 180 JPY tax), saved packVersion 1.0.0 preservation on PATCH /api/orders/:id/customer after a v1.0.1 pack upgrade for both B2C and inter-state B2B customers, and 3-decimal (KWD, BHD, OMR, JOD, TND) and 0-decimal (JPY, KRW, VND, COP) tax preview and billing calculations; all scenarios passed.Evidence: Live API and database verification transcript across all 4 scenarios
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:cart-price-overridenpm run test:order-totals-recomputenpm run test:tax-enginenpm run test:currencynpm run test:item-price-overridenpm run test:integration-taxnpm run test:community-tax-packsnpm run build && npm run build:frontendLive Playwright Chromium + Express/SQLite validation across KWD (1.234 and 0.004 overrides), JPY (1080.7 fractional override and community-japan.json 10%/8% inclusive tax), PATCH /api/orders/:id/customer after tax pack v1.0.0 -> v1.0.1 upgrade, and KWD/BHD/OMR/JOD/TND/JPY/KRW/VND/COP tax preview, order, and bill endpoints✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.