Skip to content

Use net order pricing and migrate persisted calculations - #611

Open
pozylon wants to merge 5 commits into
masterfrom
net-gross-issue
Open

Use net order pricing and migrate persisted calculations#611
pozylon wants to merge 5 commits into
masterfrom
net-gross-issue

Conversation

@pozylon

@pozylon pozylon commented Dec 13, 2024

Copy link
Copy Markdown
Member

Summary

Order category balances now exclude tax, matching the shared pricing-sheet arithmetic. Startup converts every legacy persisted order calculation, including carts and completed or rejected orders, before workers start and the platform returns ready to serve requests. The existing plugin and API initialization order is retained.

  • Preserve recorded rows, tax amounts, timestamps and metadata without repricing. Add tax offsets and explicit precision adjustments so historical gross/net balances, half-cent totals and discount breakdowns retain their values. Verify the conversion before each atomic update; retries and concurrent recalculations are safe.
  • Keep gross item revenue consistent in MCP sales summaries, monthly reports and customer-spending statistics for both migrated and newly calculated orders. Retain fractional discount entries that round to zero.
  • Run migrations even when workers are disabled. Invalid or contradictory historical calculations stop startup with the order ID; failed startup closes initialized plugins, API resources and the database connection.

Rollout

Stop older application instances before upgrading and back up the database. Rolling back to a gross-format release requires restoring that backup. Custom order adapters must pass net amounts with separate tax amounts; direct initCore integrations must execute registered migrations before serving requests. See MIGRATION.md for details.

Validation

  • Full unit and integration suite: 1,814 passed, four skipped, zero failures.
  • TypeScript package build, ESLint on changed TypeScript files and whitespace checks passed.
  • The two review reproductions now preserve the historical CHF 1.21 total and consistent gross MCP revenue.
  • HTTP GraphQL contracts cover exact gross/net category prices, discount entities, unit prices, every order status, historical rounding, empty calculations and taxable cart checkout through registered plugins.
  • Deterministic Saferpay and PostFinance contracts verify outbound amounts/currencies, payment validation and PostFinance refunds for fresh, migrated and historical rounding cases. Gateway boundaries are mocked; no credentials are needed.
  • Ran the same 14 GraphQL/payment contract tests against both the pre-net origin/master revision (e420ba74d) and this branch: 14 passed on each, no skips. All monetary expectations are identical; only test fixture storage/input amounts adapt via PRICING_CONTRACT_FORMAT=gross on the baseline. The baseline has isolated workspace dependencies and build outputs.
  • Independent differential verification matched 120,000 historical calculations against the old pricing implementation, including fractional values, multiple taxes and discounts, and every public pricing scope.

The integration setup registers the all preset, but does not exercise every bundled plugin. Optional EU/UK/US tax presets, currency conversion, mixed tax rates and discount spillover into nonzero fees still lack a complete cart integration matrix. Gateway contract tests mock the external service; they do not validate live provider behavior.

Validation also exposed an intermittent test isolation race: an enrollment notification worker can fork email work after the next test resets the database, leaving an extra WORK_ADDED event and failing six event-list/count assertions. This was reproduced independently; isolated events tests and a subsequent full run passed. No pricing assertion failed, and this PR does not change the unrelated test setup.

@pozylon
pozylon marked this pull request as draft December 13, 2024 15:37
@pozylon
pozylon force-pushed the net-gross-issue branch 2 times, most recently from 682bf7d to 813d1d6 Compare September 7, 2026 10:25
@pozylon pozylon changed the title Move to net Use net order pricing and migrate persisted calculations Sep 7, 2026
Mark net order calculations explicitly and preserve legacy gross-row semantics. Keep public totals and discount breakdowns stable, and cover the migration with a differential regression harness.
Convert recorded taxes once with atomic, resumable order updates. Run migrations before plugins and API startup, including worker-disabled instances, and reject startup on migration failure. Remove runtime legacy arithmetic and cover migration, spending statistics and startup contracts.
Record additive precision adjustments to retain legacy gross, net and discount balances across floating-point rounding boundaries. Verify each conversion before its atomic write, use gross category balances in MCP sales reports, retain fractional discount entries and close the database on migration failure.
@pozylon
pozylon marked this pull request as ready for review September 7, 2026 12:50
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.

1 participant