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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed second-round review findings in the money changes
Damian Legawiec19a2ee5a69df
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdxindex 83e2d8804e..ea1d6a5fc9 100644--- a/docs/developer/upgrades/5.6-to-6.0.mdx+++ b/docs/developer/upgrades/5.6-to-6.0.mdx@@ -657,7 +657,7 @@ Also note:- **Ransack:** `default_price` is no longer a searchable association on `Variant`; query `prices` instead.- **Prices in permitted params:** the dead `:price` and `:compare_at_price` entries are gone. Prices were already written as nested `prices: [{ amount:, currency: }]` under variants — the top-level keys had no writer behind them. (`Spree::PermittedAttributes` itself is removed in 6.0 — see below.)-- Localized number parsing still happens: `Spree::Price#amount=` runs `Spree::LocalizedNumber.parse`, so `set_price(currency, '1,599.99')` works as `price=` did.+- Prices are written as numbers or canonical decimal strings: `set_price(currency, '1599.99')`. A localized string such as `'1,599.99'` raises `Spree::Money::InvalidFormat` (see [Money](#money)).- The variant validation that inferred a missing price from the product's default variant is gone. Set prices explicitly (the product and variant factories already do).### `Spree::PermittedAttributes` is removed@@ -820,9 +820,9 @@ Other changes that come with it:## Money-- **Numbers are no longer parsed by locale.** Price, variant, payment, refund, store credit, gift card, discount and fee amounts are stored as sent. Before 6.0 they were re-read under the request's language, so a store whose language writes a comma decimal (Dutch, German, French) saved the dashboard's `49.50` as 4950, and an unchanged price grew tenfold on each save. Send canonical decimal strings (`"1234.56"`) and convert localized input in the client. `Spree::LocalizedNumber` still works with a warning until 6.1. If your prices were saved in a comma-decimal store before upgrading, check them.+- **Numbers are no longer parsed by locale.** Price, variant, payment, refund, store credit, gift card, discount and fee amounts take a number or a canonical decimal string (`"1234.56"`); any other text raises `Spree::Money::InvalidFormat`, which the API answers with `invalid_money_format`. Before 6.0 they were re-read under the request's language, so a store whose language writes a comma decimal (Dutch, German, French) saved the dashboard's `49.50` as 4950, and an unchanged price grew tenfold on each save. Send canonical decimal strings (`"1234.56"`) and convert localized input in the client. `Spree::LocalizedNumber` still works with a warning until 6.1. If your prices were saved in a comma-decimal store before upgrading, check them.- **Rounding follows the currency.** Taxes, percentage discounts, promotion splits and shipping markups round to the currency's own decimal places from the ISO 4217 table: whole yen, three decimals for dinar. Two-decimal currencies are unchanged. Open carts in other currencies may change by less than one minor unit the next time they are recalculated. Placed orders do not change. Spree now gives the Hungarian forint two decimal places, as ISO 4217 does.-- **Capture records in yen and dinar may be wrong.** A capture in a currency without two decimals could be recorded in the wrong unit: 100 times too much in yen, a tenth in dinar. To list those records, writing nothing, run:+- **Capture records in yen and dinar may be wrong.** An admin capture in a currency without two decimals is recorded in the wrong unit: 100 times too much in yen, a tenth in dinar. This is fixed when gateways start receiving amounts with their currency, later in 6.0. To list the affected records, writing nothing, run:<CodeGroup>diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.tsindex cf8a93cd86..f7bb881e16 100644--- a/packages/dashboard/e2e/helpers.ts+++ b/packages/dashboard/e2e/helpers.ts@@ -542,7 +542,8 @@ export async function createShippedOrder(page: Page, accessToken: string, quanti/*** Switches the shared admin account and this browser to a dashboard language* together, and returns a function that hands the account back its previous- * language. Call it before `login`, and the returned function in `afterEach`.+ * language. Call it before the page next loads (before `login`, or before a+ * `reload`), and the returned function in `afterEach`.** Both must agree: when they differ the auth provider reloads to bring the* browser in line with the account, and a reload during the boot refreshdiff --git a/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsxindex f2c501f695..8abbcd7ae8 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/loyalty/gift-cards.tsx@@ -10,6 +10,7 @@ import {resourceSearchSchema,StoreDatePicker,Subject,+ useMoneyLocale,usePermissions,useStore,} from '@spree/dashboard-core'@@ -36,7 +37,6 @@ import {} from '@spree/dashboard-ui'import { PlusIcon } from '@spree/dashboard-ui/icons'import { createFileRoute, useNavigate } from '@tanstack/react-router'-import i18n from 'i18next'import { useEffect, useRef } from 'react'import { Controller, type UseFormReturn, useForm } from 'react-hook-form'import { useTranslation } from 'react-i18next'@@ -424,9 +424,10 @@ function AmountCurrencyRow<T extends GiftCardCreateFormValues | GiftCardEditForm}) {const { t } = useTranslation()const errors = form.formState.errors as Record<string, { message?: string } | undefined>+ const moneyLocale = useMoneyLocale()const { symbol: currencySymbol } = currencyParts((form.watch('currency' as never) as unknown as string) || 'USD',- i18n.language,+ moneyLocale,)return (<div className="grid grid-cols-2 gap-3">diff --git a/packages/dashboard/src/schemas/gift-card.ts b/packages/dashboard/src/schemas/gift-card.tsindex 68c1371d09..e4e081cbd8 100644--- a/packages/dashboard/src/schemas/gift-card.ts+++ b/packages/dashboard/src/schemas/gift-card.ts@@ -18,8 +18,8 @@ const currencyRequired = () =>i18n.t('admin.pages.promotions.gift_cards.validation.currency_required')// Amounts stay STRINGS, from a number input that always yields a canonical-// value ("49.5"); `Number()` coercion would lose precision. "Is positive" is-// still checked with a lightweight string regex.+// value ("49.5"), and are sent as typed. `Number()` is used only to check the+// value is positive, never to compute or send an amount.const positiveAmountString = z.string().refine((s) => {const n = Number(s.replace(',', '.'))diff --git a/spree/api/app/controllers/concerns/spree/api/v3/money_params.rb b/spree/api/app/controllers/concerns/spree/api/v3/money_params.rbindex 2aecb3887c..58ed123448 100644--- a/spree/api/app/controllers/concerns/spree/api/v3/money_params.rb+++ b/spree/api/app/controllers/concerns/spree/api/v3/money_params.rb@@ -19,7 +19,10 @@ module Spree# @return [BigDecimal, nil] nil when the parameter is absent# @raise [Spree::Money::InvalidFormat]def money_param(name, currency, unit_price: false)- Spree::Money::Rounding.parse_canonical(params[name], currency, unit_price: unit_price)+ value = params[name]+ # JSON numbers stay accepted until the 6.0 wire contract (money plan, PR B).+ value = value.to_s if value.is_a?(Integer) || value.is_a?(Float)+ Spree::Money::Rounding.parse_canonical(value, currency, unit_price: unit_price)rescue Spree::Money::InvalidFormat => errorraise Spree::Money::InvalidFormat.new(error.message, field: name)enddiff --git a/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rbindex 879d876d5d..00a54b0645 100644--- a/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb@@ -67,6 +67,15 @@ module Spree)end+ if (malformed = result.error&.value.try(:[], :malformed_amounts))+ return render_error(+ code: Spree::Api::V3::ErrorHandler::ERROR_CODES[:invalid_money_format],+ message: I18n.t('activerecord.errors.models.spree/price_list.attributes.base.malformed_price').upcase_first,+ status: :unprocessable_content,+ details: { rows: malformed }+ )+ end+if (negative = result.error&.value.try(:[], :invalid_amounts))return render_error(code: 'invalid_amount',diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rbindex 559e85a34f..8e5b4c135d 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders/payments_controller_spec.rb@@ -176,6 +176,12 @@ RSpec.describe Spree::Api::V3::Admin::Orders::PaymentsController, type: :controlendcontext 'with a partial amount' do+ it 'still accepts a JSON number' do+ expect(Spree.payment_capture_workflow).to receive(:call).with(payment: payment, amount: 115).and_call_original++ patch :capture, params: { order_id: order_with_payment.prefixed_id, id: payment.prefixed_id, amount: 1.15 }, as: :json+ end+it 'hands the gateway exact hundredths' doexpect(Spree.payment_capture_workflow).to receive(:call).with(payment: payment, amount: 115).and_call_original@@ -186,7 +192,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::PaymentsController, type: :control}, as: :jsonend- [1.15, '1,15', '1.155', '-5.00', '0'].each do |amount|+ ['1,15', '1.155', '-5.00', '0', 'abc'].each do |amount|it "refuses #{amount.inspect} with invalid_money_format" doexpect(Spree.payment_capture_workflow).not_to receive(:call)diff --git a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rbindex 565714e5aa..f80f8a3a4b 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb@@ -848,6 +848,17 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller doexpect(save_price('49.50')).to eq(BigDecimal('49.50'))end+ it 'refuses an amount it would otherwise misread' do+ patch :update, params: {+ id: product.prefixed_id,+ variants: [{ id: variant.prefixed_id, prices: [{ currency: 'USD', amount: '1,599.99' }] }]+ }, as: :json++ expect(response).to have_http_status(:unprocessable_content)+ expect(json_response['error']['code']).to eq('invalid_money_format')+ expect(json_response['error']['details']).to have_key('amount')+ end+it 'keeps a price stable across repeated saves of what the API returned' dosave_price('99')returned = json_response['variants']&.first&.dig('prices')&.first&.dig('amount') ||diff --git a/spree/core/app/models/concerns/spree/canonical_decimals.rb b/spree/core/app/models/concerns/spree/canonical_decimals.rbnew file mode 100644index 0000000000..756adc5861--- /dev/null+++ b/spree/core/app/models/concerns/spree/canonical_decimals.rb@@ -0,0 +1,25 @@+module Spree+ # Decimal attributes written as a number or canonical decimal text+ # ("1234.56"). Text in any other shape raises Spree::Money::InvalidFormat,+ # which the API answers as `invalid_money_format`, instead of being read as+ # a wrong number the way Rails' cast reads "1,599.99" as 1 and "$10" as 0.+ module CanonicalDecimals+ extend ActiveSupport::Concern++ class_methods do+ # @param names [Array<Symbol>]+ # @param ignore_blank [Boolean] leave the attribute as it was when given a blank+ def canonical_decimals(*names, ignore_blank: false)+ names.each do |name|+ define_method("#{name}=") do |value|+ next if ignore_blank && value.blank?++ super(Spree::Money::Rounding.parse_decimal(value))+ rescue Spree::Money::InvalidFormat => error+ raise Spree::Money::InvalidFormat.new(error.message, field: name)+ end+ end+ end+ end+ end+enddiff --git a/spree/core/app/models/concerns/spree/typed_adjustment_line.rb b/spree/core/app/models/concerns/spree/typed_adjustment_line.rbindex 3710bcd20b..1ffbeebdde 100644--- a/spree/core/app/models/concerns/spree/typed_adjustment_line.rb+++ b/spree/core/app/models/concerns/spree/typed_adjustment_line.rb@@ -1,11 +1,14 @@module Spree# Shared shape of the typed adjustment rows (TaxLine, Discount, Fee):# dual-FK cart/order owner (exactly one), consolidated +metadata+ JSON- # column, money display and localized amount parsing.+ # column, money display and strict amount parsing.module TypedAdjustmentLineextend ActiveSupport::Concernincluded do+ include Spree::CanonicalDecimals++ canonical_decimals :amountattribute :metadata, default: -> { {} }belongs_to :order, class_name: 'Spree::Order', optional: truediff --git a/spree/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb b/spree/core/app/models/spree/calculator/shipping/flat_percent_item_total.rbindex 2de28a1c4a..a60d1a8a9b 100644--- a/spree/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb+++ b/spree/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb@@ -8,7 +8,7 @@ module Spreeenddef compute_package(package)- compute_from_price(total(package.contents), package.owner&.currency)+ compute_from_price(total(package.contents), package.currency)end# @param price [BigDecimal]diff --git a/spree/core/app/models/spree/gift_card.rb b/spree/core/app/models/spree/gift_card.rbindex 7a65770360..17adddaed6 100644--- a/spree/core/app/models/spree/gift_card.rb+++ b/spree/core/app/models/spree/gift_card.rb@@ -5,6 +5,9 @@ module Spreeextend DisplayMoneyinclude Spree::SingleStoreResourceinclude Spree::HasCustomFields+ include Spree::CanonicalDecimals++ canonical_decimals :amountinclude Spree::Security::GiftCards if defined?(Spree::Security::GiftCards)publishes_lifecycle_eventsdiff --git a/spree/core/app/models/spree/gift_card_batch.rb b/spree/core/app/models/spree/gift_card_batch.rbindex e87339a690..57c59f755a 100644--- a/spree/core/app/models/spree/gift_card_batch.rb+++ b/spree/core/app/models/spree/gift_card_batch.rb@@ -4,6 +4,9 @@ module Spreeextend DisplayMoneyinclude Spree::SingleStoreResource+ include Spree::CanonicalDecimals++ canonical_decimals :amountpublishes_lifecycle_eventsdiff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rbindex 5f6b040e92..ae8308281c 100644--- a/spree/core/app/models/spree/order.rb+++ b/spree/core/app/models/spree/order.rb@@ -415,9 +415,9 @@ module Spree# Returns the subtotal used for analytics integrations# It's a sum of the item total and the promo total- # @return [BigDecimal]+ # @return [Float] a JSON number, as analytics providers expectdef analytics_subtotal- item_total + line_items.sum(:discount_total)+ (item_total + line_items.sum(:discount_total)).to_fenddiff --git a/spree/core/app/models/spree/payment.rb b/spree/core/app/models/spree/payment.rbindex dd393e7098..a510879761 100644--- a/spree/core/app/models/spree/payment.rb+++ b/spree/core/app/models/spree/payment.rb@@ -6,6 +6,9 @@ module Spreederives_number infix: 'P'include Spree::HasCustomFieldsinclude Spree::Metadata+ include Spree::CanonicalDecimals++ canonical_decimals :amountif defined?(Spree::Security::Payments)include Spree::Security::Paymentsenddiff --git a/spree/core/app/models/spree/price.rb b/spree/core/app/models/spree/price.rbindex e39567213a..070e076c22 100644--- a/spree/core/app/models/spree/price.rb+++ b/spree/core/app/models/spree/price.rb@@ -11,6 +11,9 @@ module Spreeinclude Spree::VatPriceCalculationinclude Spree::StorePreferences+ include Spree::CanonicalDecimals++ canonical_decimals :amount, :compare_at_amountpublishes_lifecycle_eventsdiff --git a/spree/core/app/models/spree/refund.rb b/spree/core/app/models/spree/refund.rbindex 9c72e57edc..b08a0a31b2 100644--- a/spree/core/app/models/spree/refund.rb+++ b/spree/core/app/models/spree/refund.rb@@ -5,6 +5,9 @@ module Spreeinclude Spree::ActedByinclude Spree::HasCustomFieldsinclude Spree::Metadata+ include Spree::CanonicalDecimals++ canonical_decimals :amountinclude Spree::InstrumentsGatewayCallsif defined?(Spree::Security::Refunds)include Spree::Security::Refundsdiff --git a/spree/core/app/models/spree/store_credit.rb b/spree/core/app/models/spree/store_credit.rbindex 907939a95f..59d27737ea 100644--- a/spree/core/app/models/spree/store_credit.rb+++ b/spree/core/app/models/spree/store_credit.rb@@ -5,6 +5,9 @@ module Spreeinclude Spree::SingleStoreResourceinclude Spree::HasCustomFieldsinclude Spree::Metadata+ include Spree::CanonicalDecimals++ canonical_decimals :amountpublishes_lifecycle_eventsdiff --git a/spree/core/app/models/spree/variant.rb b/spree/core/app/models/spree/variant.rbindex 3b83321ea2..edf293bec5 100644--- a/spree/core/app/models/spree/variant.rb+++ b/spree/core/app/models/spree/variant.rb@@ -8,6 +8,7 @@ module Spreeinclude Spree::MemoizedDatainclude Spree::HasCustomFieldsinclude Spree::Metadata+ include Spree::CanonicalDecimalsinclude Spree::HasExternalReferencesinclude Spree::Searchableinclude Spree::StorePreferences@@ -290,13 +291,7 @@ module Spreeend# A blank value leaves these as they were rather than clearing them.- KEPT_WHEN_BLANK = %w(cost_price weight depth width height)-- KEPT_WHEN_BLANK.each do |m|- define_method("#{m}=") do |argument|- super(argument) if argument.present?- end- end+ canonical_decimals :cost_price, :weight, :depth, :width, :height, ignore_blank: trueaccepts_nested_attributes_for(:stock_levels,diff --git a/spree/core/app/presenters/spree/csv/product_variant_presenter.rb b/spree/core/app/presenters/spree/csv/product_variant_presenter.rbindex 3586a97f9e..da23ceb22c 100644--- a/spree/core/app/presenters/spree/csv/product_variant_presenter.rb+++ b/spree/core/app/presenters/spree/csv/product_variant_presenter.rb@@ -101,14 +101,14 @@ module Spreeunit_price(variant.amount_in(currency) || 0),unit_price(variant.compare_at_amount_in(currency) || 0),currency,- variant.width,- variant.height,- variant.depth,+ decimal(variant.width),+ decimal(variant.height),+ decimal(variant.depth),# The stored columns, not the resolved readers: importing this file# into a store on another unit system must not silently write this# store's units onto every variant.variant[:dimensions_unit],- variant.weight,+ decimal(variant.weight),variant[:weight_unit],publication_available_on&.strftime('%Y-%m-%d %H:%M:%S'),(variant.discontinue_on || publication_discontinue_on)&.strftime('%Y-%m-%d %H:%M:%S'),@@ -155,6 +155,11 @@ module SpreeSpree::Money::Rounding.format(amount, currency, unit_price: true)end+ # "1.5", never Ruby's "0.15e1", which the import refuses.+ def decimal(value)+ Spree::Money::Rounding.format_decimal(value)+ end+# Default-channel publication for the export's store. 5.5 transitional:# fall back to the legacy Product columns when the publication dates are# NULL (pre-backfill). 6.0 drops the Product-column fallback.diff --git a/spree/core/app/services/spree/prices/bulk_upsert.rb b/spree/core/app/services/spree/prices/bulk_upsert.rbindex d1b101bbcb..12c1807835 100644--- a/spree/core/app/services/spree/prices/bulk_upsert.rb+++ b/spree/core/app/services/spree/prices/bulk_upsert.rb@@ -44,9 +44,12 @@ module Spree# (docs/plans/6.0-volume-pricing.md).def call(rows:)rows = Array(rows).map { |r| r.with_indifferent_access }- # Amounts are parsed once, here; everything below reads numbers.keyed = rows.select { |r| r[:variant_id].present? && r[:currency].present? }- .map { |r| r.merge(amount: Spree::Money::Rounding.parse_decimal(r[:amount]), compare_at_amount: Spree::Money::Rounding.parse_decimal(r[:compare_at_amount])) }+ unreadable = rows_with_malformed_amount(keyed)+ return failure(nil, malformed_amounts: unreadable) if unreadable.any?++ # Amounts are parsed once, here; everything below reads numbers.+ keyed = keyed.map { |r| r.merge(amount: Spree::Money::Rounding.parse_decimal(r[:amount]), compare_at_amount: Spree::Money::Rounding.parse_decimal(r[:compare_at_amount])) }# Checked before anything is deduped: `row_key` coerces the quantity,# so two malformed rows would collapse into one and the batch would be# judged on a shape the caller never sent.@@ -170,6 +173,17 @@ module Spree# Rows pricing below zero. This path runs no model validations, so the# sign is checked here for every caller rather than in each of them.+ # Rows whose amount is text that is not a plain decimal ("1,599.99").+ def rows_with_malformed_amount(rows)+ rows.each_with_index.filter_map do |row, index|+ Spree::Money::Rounding.parse_decimal(row[:amount])+ Spree::Money::Rounding.parse_decimal(row[:compare_at_amount])+ nil+ rescue Spree::Money::InvalidFormat+ { index: index }+ end+ end+def rows_with_negative_amount(rows)rows.each_with_index.filter_map do |row, index|{ index: index } if row[:amount]&.negative? || row[:compare_at_amount]&.negative?diff --git a/spree/core/app/workflows/spree/price_lists/update.rb b/spree/core/app/workflows/spree/price_lists/update.rbindex f6386cf25f..97ac886952 100644--- a/spree/core/app/workflows/spree/price_lists/update.rb+++ b/spree/core/app/workflows/spree/price_lists/update.rb@@ -72,7 +72,9 @@ module Spreeunless result.success?refusal = result.error&.valuerefusal = {} unless refusal.is_a?(Hash)- if refusal[:invalid_amounts].present?+ if refusal[:malformed_amounts].present?+ price_list.errors.add(:base, :malformed_price)+ elsif refusal[:invalid_amounts].present?price_list.errors.add(:base, :negative_price)elsif refusal[:invalid_quantities].present?price_list.errors.add(:base, :invalid_quantity)diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.ymlindex 99f678e11f..89bd6e6c2c 100644--- a/spree/core/config/locales/en.yml+++ b/spree/core/config/locales/en.yml@@ -381,6 +381,7 @@ en:base:duplicate_quantity: each quantity break must have its own quantityinvalid_quantity: each quantity break must start at a whole number of units+ malformed_price: a price must be a number like 16.50negative_price: a price cannot be below zeronothing_to_apply_to: has no rules, no catalog and no products, so it would apply to nothing. Add one before activating.price_rises_with_quantity: a quantity break cannot cost more than the price a buyer pays below itdiff --git a/spree/core/spec/models/spree/payment_spec.rb b/spree/core/spec/models/spree/payment_spec.rbindex 5e8473d626..944d720e09 100644--- a/spree/core/spec/models/spree/payment_spec.rb+++ b/spree/core/spec/models/spree/payment_spec.rb@@ -1087,13 +1087,11 @@ describe Spree::Payment, type: :model doendend- context 'amount is invalid' do- let(:amount) { 'invalid' }+ context 'amount is not a number' do+ let(:amount) { nil }- # this is a strange default for ActiveRecord-- it '#amount' do- expect(subject.amount).to eql(BigDecimal('0'))+ it 'is refused instead of being read as zero' do+ expect { subject.amount = 'invalid' }.to raise_error(Spree::Money::InvalidFormat)endenddiff --git a/spree/core/spec/models/spree/price_spec.rb b/spree/core/spec/models/spree/price_spec.rbindex c476d89bad..c95f794e40 100644--- a/spree/core/spec/models/spree/price_spec.rb+++ b/spree/core/spec/models/spree/price_spec.rb@@ -119,6 +119,10 @@ describe Spree::Price, type: :model doexpect(price.amount).to eq(BigDecimal('49.50'))end+ it 'refuses text it would otherwise misread, naming the attribute' do+ expect { price.amount = '1,599.99' }.to raise_error(Spree::Money::InvalidFormat) { |error| expect(error.field).to eq(:amount) }+ end+it 'does not grow when what it read back is saved again' doI18n.with_locale(:nl) { price.amount = '99.0' }expect(price.amount).to eq(BigDecimal('99'))diff --git a/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb b/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rbindex 0402d5c7bb..f5560f5870 100644--- a/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb+++ b/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb@@ -31,11 +31,11 @@ RSpec.describe Spree::CSV::ProductVariantPresenter doexpect(subject[12]).to eq '19.99'expect(subject[13]).to eq '0.00'expect(subject[14]).to eq store.default_currency- expect(subject[15]).to eq variant.width- expect(subject[16]).to eq variant.height- expect(subject[17]).to eq variant.depth+ expect(subject[15]).to eq Spree::Money::Rounding.format_decimal(variant.width)+ expect(subject[16]).to eq Spree::Money::Rounding.format_decimal(variant.height)+ expect(subject[17]).to eq Spree::Money::Rounding.format_decimal(variant.depth)expect(subject[18]).to eq 'in'- expect(subject[19]).to eq variant.weight+ expect(subject[19]).to eq Spree::Money::Rounding.format_decimal(variant.weight)expect(subject[20]).to eq 'lb'expect(subject[21]).to eq default_publication.published_at&.strftime('%Y-%m-%d %H:%M:%S')expect(subject[22]).to eq(diff --git a/spree/core/spec/services/spree/prices/bulk_upsert_spec.rb b/spree/core/spec/services/spree/prices/bulk_upsert_spec.rbindex a317a11a89..b219d7f689 100644--- a/spree/core/spec/services/spree/prices/bulk_upsert_spec.rb+++ b/spree/core/spec/services/spree/prices/bulk_upsert_spec.rb@@ -129,11 +129,11 @@ RSpec.describe Spree::Prices::BulkUpsert doexpect(base.amount).to eq(BigDecimal('7.77'))end- it 'refuses an amount it would otherwise misread' do- expect {- described_class.call(rows: [{ variant_id: variant.id, currency: 'USD', amount: '1,599.99' }])- }.to raise_error(Spree::Money::InvalidFormat)- expect(variant.prices.find_by(currency: 'USD', price_list_id: nil)&.amount).not_to eq(BigDecimal('1'))+ it 'refuses an amount it would otherwise misread, naming the row' do+ result = described_class.call(rows: [{ variant_id: variant.id, currency: 'USD', amount: '1,599.99' }])++ expect(result).to be_failure+ expect(result.error.value).to eq(malformed_amounts: [{ index: 0 }])endit 'drops rows missing variant_id or currency' dodiff --git a/spree/providers/easypost/lib/spree_easypost.rb b/spree/providers/easypost/lib/spree_easypost.rbindex 2dbe80e192..e9bdd1222d 100644--- a/spree/providers/easypost/lib/spree_easypost.rb+++ b/spree/providers/easypost/lib/spree_easypost.rb@@ -195,7 +195,7 @@ module SpreeEasyPost{description: variant.customs_description_for_declaration,quantity: item.quantity,- value: Spree::Money::Rounding.to_currency(item.price * item.quantity, package.owner&.currency).to_f, # EasyPost reads customs values as JSON numbers+ value: Spree::Money::Rounding.to_currency(item.price * item.quantity, package.currency).to_f, # EasyPost reads customs values as JSON numbersweight: ounces(item.weight, store),origin_country: variant.country_of_origin.presence,hs_tariff_number: variant.hs_code.presence,