Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Updated the money plan for strict money setters

Damian Legawiecda26594f85e5
diff --git a/docs/plans/6.0-money-correctness.md b/docs/plans/6.0-money-correctness.md
index 48ff0ed2a9..befdca0764 100644
--- a/docs/plans/6.0-money-correctness.md
+++ b/docs/plans/6.0-money-correctness.md
@@ -30,7 +30,7 @@ All decided 2026-10-08; the ones marked *review* were changed or added after the
- **Wrong capture events are reported, not repaired.** `spree:money:audit_capture_events` lists payments in non-two-decimal currencies whose capture events disagree with the corrected value, and writes nothing. Spree never rewrites money on completed orders.
- **The rule lives in `CLAUDE.md`, not in a lint tool** (decided 2026-10-09; supersedes the first pass's RuboCop cop and Biome twin). A cop was built and then dropped: the repository runs no RuboCop, and a name-matching rule needs an allowlist that is mostly noise. `CLAUDE.md` "Money" states it for people and agents alike.
- **Open carts in zero- and three-decimal currencies change on their next recalculation.** Accepted trade-off: a yen total can move by under one yen mid-checkout. Completed orders are frozen and do not change.
-- **Spree stops parsing numbers by locale** (decided 2026-10-09; supersedes the 5.5 plan's "`LocalizedNumber` is not removed" and this plan's first-pass "out of scope"). The model setters that re-parsed strings with `Spree::LocalizedNumber` under the request locale are removed, and Rails' decimal type reads the value as sent. Why: the legacy admin they served is gone, and under a store whose language writes a comma decimal they misread the dashboard's canonical `"49.50"` as 4950 and grew an untouched `"99.0"` tenfold on every save (a reported bug). `Spree::LocalizedNumber.parse` stays one release as a deprecated method nothing in Spree calls, and is removed in 6.1. The variant's `cost_price`/`weight`/`width`/`height`/`depth` writers keep ignoring a blank value. Ships in PR A.
+- **Spree stops parsing numbers by locale** (decided 2026-10-09; supersedes the 5.5 plan's "`LocalizedNumber` is not removed" and this plan's first-pass "out of scope"). The model setters that re-parsed strings with `Spree::LocalizedNumber` under the request locale are replaced by strict ones (`Spree::CanonicalDecimals`): a number or canonical decimal text is stored exactly, and any other text raises `Spree::Money::InvalidFormat` (422 `invalid_money_format` from the API) instead of Rails' lenient cast reading `"1,599.99"` as 1. Why: the legacy admin they served is gone, and under a store whose language writes a comma decimal they misread the dashboard's canonical `"49.50"` as 4950 and grew an untouched `"99.0"` tenfold on every save (a reported bug). `Spree::LocalizedNumber.parse` stays one release as a deprecated method nothing in Spree calls, and is removed in 6.1. The variant's `cost_price`/`weight`/`width`/`height`/`depth` writers keep ignoring a blank value. Ships in PR A.
- **The dashboard shows and reads money in the admin's own number format** (decided 2026-10-09, following Shopify; supersedes the 5.5 plan's "currency's market locale"). `useMoneyLocale()` returns the dashboard language; every money field formats and normalizes through it, whatever the currency or market. Why: a store can have several markets with one currency and different conventions (EUR in Germany and Ireland), so the market-based format depended on which market loaded first; the person typing knows their own convention, and the old reason against it, server re-parsing, is gone. Accepted trade-off: a German-speaking admin of a US store sees `1234,56` for dollars. Ships in PR A.
- **PR A applies the ISO table to Spree's own rounding only; registering it over the Money gem moves to A2** (decided 2026-10-09). Registering changes `Money#cents` for HUF, which Stripe payment sessions read, and A2 is the only PR that may change what a gateway receives.
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 67cb26e670..c67cfd5923 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -2,9 +2,9 @@
**Context:** Price, variant, payment, refund, store credit, gift card and adjustment setters re-parsed every string with `Spree::LocalizedNumber` under the request's locale, for the legacy Rails admin. That admin is gone. In a store whose language writes a comma decimal (nl, de, fr) the setters read the dashboard's canonical `"49.50"` as 4950, and an untouched `"99.0"` grew tenfold on every save.
-**Decision:** The locale-parsing setters are removed; Rails' decimal type stores the value as sent. `Spree::LocalizedNumber.parse` is deprecated with a warning and removed in 6.1. Clients normalize localized input before sending (5.5 plan). The dashboard shows and reads money in the admin's own dashboard language, whatever the currency or market (as Shopify does), instead of the currency's market locale, which was ambiguous when markets share a currency.
+**Decision:** The locale-parsing setters are replaced by strict ones: a number or canonical decimal text is stored exactly, and any other text raises `Spree::Money::InvalidFormat` rather than being silently misread. `Spree::LocalizedNumber.parse` is deprecated with a warning and removed in 6.1. Clients normalize localized input before sending (5.5 plan). The dashboard shows and reads money in the admin's own dashboard language, whatever the currency or market (as Shopify does), instead of the currency's market locale, which was ambiguous when markets share a currency.
-**Consequences:** A localized string sent to a model (`"1.234,56"`) is no longer understood; the Admin API never accepted it by contract. Supersedes the 5.5 plan's "`LocalizedNumber.parse` is NOT removed". See `6.0-money-correctness.md`.
+**Consequences:** A localized string sent to a model (`"1.234,56"`) is refused with `invalid_money_format`; the Admin API never accepted it by contract. Supersedes the 5.5 plan's "`LocalizedNumber.parse` is NOT removed". See `6.0-money-correctness.md`.
## 2026-10-08: Money is BigDecimal end to end, gateways get amount plus currency, strict canonical strings on the wire, and decimal(19,4) in the database