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
Fix: Charge market prices as entered for buyers abroad (#14833)
Łukasz Adamczykb38df6ef3efc
diff --git a/.changeset/admin-sdk-tax-rate-included-in-price.md b/.changeset/admin-sdk-tax-rate-included-in-price.mdnew file mode 100644index 0000000000..24be2edb37--- /dev/null+++ b/.changeset/admin-sdk-tax-rate-included-in-price.md@@ -0,0 +1,5 @@+---+"@spree/admin-sdk": minor+---++Tax rates no longer have `included_in_price`, in responses, create and update params, filters or sort. Whether prices include tax is now the market's `tax_inclusive` setting.diff --git a/.changeset/dashboard-prices-include-tax.md b/.changeset/dashboard-prices-include-tax.mdnew file mode 100644index 0000000000..7f5b12fc44--- /dev/null+++ b/.changeset/dashboard-prices-include-tax.md@@ -0,0 +1,5 @@+---+"@spree/dashboard": patch+---++The market form's tax switch is now "Prices include tax" and decides whether customers pay the price as entered with tax inside it or have tax added at checkout. The tax rate form and list no longer show "Included in price".diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yamlindex fc01bc6918..02ebb56436 100644--- a/docs/api-reference/admin.yaml+++ b/docs/api-reference/admin.yaml@@ -30830,9 +30830,9 @@ paths:description: |-Returns the store's tax rates. Rates are the entire configuration ofthe built-in tax provider: each pairs a tax category with a jurisdiction- (a country, optionally narrowed to one state) and a percentage, and- decides whether the tax is already included in the product price- (VAT-style) or added on top (US-style).+ (a country, optionally narrowed to one state) and a percentage. Whether+ the tax is included in the product price (VAT-style) or added on top+ (US-style) is the market's `tax_inclusive` setting.Markets using an external tax provider ignore these rows — thatprovider carries its own jurisdiction data.@@ -30912,13 +30912,12 @@ paths:| `country_code` | Text | `eq` `not_eq` `in` `not_in` `cont` `i_cont` `not_cont` `start` `end` `null` `not_null` `present` `blank` || `created_at` | Date and time | `eq` `not_eq` `in` `not_in` `lt` `lteq` `gt` `gteq` `null` `not_null` || `id` | Prefixed ID | `eq` `not_eq` `in` `not_in` `null` `not_null` |- | `included_in_price` | True or false | `eq` `not_eq` `in` `not_in` `true` `false` `null` || `name` | Text | `eq` `not_eq` `in` `not_in` `cont` `i_cont` `not_cont` `start` `end` `null` `not_null` `present` `blank` || `state_code` | Text | `eq` `not_eq` `in` `not_in` `cont` `i_cont` `not_cont` `start` `end` `null` `not_null` `present` `blank` || `tax_category_id` | Prefixed ID | `eq` `not_eq` `in` `not_in` `null` `not_null` || `updated_at` | Date and time | `eq` `not_eq` `in` `not_in` `lt` `lteq` `gt` `gteq` `null` `not_null` |- **Sort by:** `amount`, `country_code`, `created_at`, `id`, `included_in_price`, `name`, `state_code`, `tax_category_id`, `updated_at`. Prefix a field with `-` to sort descending.+ **Sort by:** `amount`, `country_code`, `created_at`, `id`, `name`, `state_code`, `tax_category_id`, `updated_at`. Prefix a field with `-` to sort descending.x-spree-filters:table: TaxRatesortable:@@ -30926,7 +30925,6 @@ paths:- country_code- created_at- id- - included_in_price- name- rate- state_code@@ -30941,7 +30939,6 @@ paths:data:- id: tax_UkLWZg9DAJname: TaxRate - 124492- included_in_price: trueshow_rate_in_label: truemetadata: {}created_at: '2026-01-15T12:00:00.000Z'@@ -30999,9 +30996,6 @@ paths:Name the jurisdiction with `country_code` (and `state_code` for astate-level rate). Omitting the country makes the rate apply everywhere.- Set `included_in_price` for VAT-style pricing, where the rate is backed- out of the displayed price rather than added to it.-**Required scope:** `write_settings` (for API-key authentication).x-codeSamples:@@ -31046,7 +31040,6 @@ paths:example:id: tax_gbHJdmfrXBname: VAT- included_in_price: trueshow_rate_in_label: truemetadata: {}created_at: '2026-01-15T12:00:00.000Z'@@ -31136,7 +31129,6 @@ paths:example:id: tax_UkLWZg9DAJname: TaxRate - 312890- included_in_price: trueshow_rate_in_label: truemetadata: {}created_at: '2026-01-15T12:00:00.000Z'@@ -31193,7 +31185,6 @@ paths:example:id: tax_UkLWZg9DAJname: TaxRate - 470830- included_in_price: trueshow_rate_in_label: truemetadata: {}created_at: '2026-01-15T12:00:00.000Z'@@ -72907,8 +72898,6 @@ components:type: stringname:type: string- included_in_price:- type: booleanshow_rate_in_label:type: booleanmetadata:@@ -73183,7 +73172,6 @@ components:required:- id- name- - included_in_price- show_rate_in_label- metadata- created_at@@ -78411,7 +78399,9 @@ components:example: detax_inclusive:type: boolean- description: Display prices with tax included.+ description: Whether the prices entered for this market include tax. True+ charges every customer the price as entered, with their tax inside it;+ false adds tax at checkout.tax_provider:type: stringdescription: Shorthand of the tax engine that prices this market, from the@@ -78466,7 +78456,9 @@ components:example: detax_inclusive:type: boolean- description: Display prices with tax included.+ description: Whether the prices entered for this market include tax. True+ charges every customer the price as entered, with their tax inside it;+ false adds tax at checkout.tax_provider:type: stringdescription: Shorthand of the tax engine that prices this market, from the@@ -82425,8 +82417,6 @@ components:pattern: "^-?\\d+(\\.\\d+)?$"description: The rate as a percentage.example: '19'- included_in_price:- type: booleanshow_rate_in_label:type: booleantax_category_id:@@ -82467,8 +82457,6 @@ components:pattern: "^-?\\d+(\\.\\d+)?$"description: The rate as a percentage.example: '19'- included_in_price:- type: booleanshow_rate_in_label:type: booleantax_category_id:@@ -84336,7 +84324,6 @@ components:country_code: textcreated_at: datetimeid: id- included_in_price: booleanname: textrate: decimalstate_code: textdiff --git a/docs/developer/core-concepts/markets.mdx b/docs/developer/core-concepts/markets.mdxindex 017b6ede57..4fb02469a6 100644--- a/docs/developer/core-concepts/markets.mdx+++ b/docs/developer/core-concepts/markets.mdx@@ -44,7 +44,7 @@ erDiagram| `currency` | ISO 4217 currency code | `USD` || `default_locale` | Default language for this market | `en` || `supported_locales` | All locales available in this market | `["en", "es"]` |-| `tax_inclusive` | Whether prices include tax (affects display and checkout calculation) | `false` |+| `tax_inclusive` | Whether the prices entered for this market include tax | `false` || `default` | Whether this is the fallback market when no country match is found | `true` || `country_codes` | Countries in this market, as ISO codes | `["US", "CA"]` |@@ -220,12 +220,23 @@ See [Localization](/api-reference/store-api/localization) for details on how to## Tax Behavior-The `tax_inclusive` flag on a market controls how prices are displayed and calculated:+The `tax_inclusive` flag on a market decides whether the prices entered for it include tax:-- **`tax_inclusive: true`** (common in Europe) — the price shown to the customer already includes tax-- **`tax_inclusive: false`** (common in the US) — tax is added at checkout on top of the displayed price+- **`tax_inclusive: true`** (common in Europe) — every customer pays the price as entered, with their country's tax inside it+- **`tax_inclusive: false`** (common in the US) — tax is added at checkout on top of the price-This matters because prices are shown long before anyone knows where the shopper lives. The market's own country supplies the assumed rate for browsing; once a shipping address is entered at checkout, that address takes over and the real rate applies.+The same price is charged to every customer of the market, wherever they are. Take a €100.00 price in a market covering Germany (19%) and France (20%):++| `tax_inclusive` | Customer in Germany pays | Customer in France pays |+|---|---|---|+| `true` | €100.00, of which €15.97 is VAT | €100.00, of which €16.67 is VAT |+| `false` | €119.00: €100.00 plus €19.00 VAT | €120.00: €100.00 plus €20.00 VAT |++Tax rates only hold the percentage for each country; the market decides whether that tax is inside the price. Spree's own tax tables and external tax providers both read the market's setting, and each order's tax lines record whether their tax was included, so editing a market later never changes an order already placed. A storefront can read `tax_inclusive` from the market to tell the shopper whether the price they see includes tax.++Prices are never adjusted for customers in another country. To charge some countries a different price, put them in a market of their own and give it a [price list](/developer/core-concepts/pricing#price-rules) with a Market Rule.++Before a customer enters an address, the market's first country by name supplies the tax rate; once a shipping address is entered at checkout, that address takes over and the real rate applies.A market also chooses **which tax provider works out its numbers** — Spree's own rate tables in a simple market, an external tax service in a complicated one. See [Taxes](/developer/core-concepts/taxes).diff --git a/docs/developer/core-concepts/taxes.mdx b/docs/developer/core-concepts/taxes.mdxindex 86b70894c1..a4cfb7ebc0 100644--- a/docs/developer/core-concepts/taxes.mdx+++ b/docs/developer/core-concepts/taxes.mdx@@ -58,13 +58,12 @@ curl -X POST 'https://api.mystore.com/api/v3/admin/tax_categories' \## Tax rates-A tax rate is the number itself, plus where it applies and whether it's already in the price.+A tax rate is the number itself, plus where it applies. Whether it is already in the price is the [market's](/developer/core-concepts/markets#tax-behavior) choice, not the rate's.| Field | Description | Example ||---|---|---|| `name` | What appears on the invoice | `VAT 20%` || `amount` | The rate as a decimal | `0.2` for 20% |-| `included_in_price` | Whether the price already contains it | `true` in the EU || `country_code` / `state_code` | Where it applies | `DE`, or `US` + `CA` || `tax_category` | What it applies to | `Standard` |@@ -76,7 +75,6 @@ const { data: rates } = await adminClient.taxRates.list()await adminClient.taxRates.create({name: 'VAT 20%',amount: '0.2',- included_in_price: true,country_code: 'GB',tax_category_id: 'taxcat_xxx',})@@ -94,7 +92,6 @@ curl -X POST 'https://api.mystore.com/api/v3/admin/tax_rates' \-d '{"name": "VAT 20%","amount": "0.2",- "included_in_price": true,"country_code": "GB","tax_category_id": "taxcat_xxx"}'@@ -106,7 +103,7 @@ Rates name their country and state by **ISO code**, not by an ID — `DE`, `US`## Included or added on-`included_in_price` is the single most consequential setting here, so it's worth being precise about what it does.+A market's `tax_inclusive` setting is the single most consequential setting here, so it's worth being precise about what it does.<Tabs><Tab title="Added on (US style)">@@ -120,7 +117,7 @@ Rates name their country and state by **ISO code**, not by an ID — `DE`, `US`| Tax added | $0.90 || Customer pays | **$18.89** |- Set `included_in_price: false`.+ Set `tax_inclusive: false` on the market.</Tab><Tab title="Included (EU style)">The shelf price is the whole price. The tax inside it is shown for information — the customer pays the number they saw.@@ -133,7 +130,7 @@ Rates name their country and state by **ISO code**, not by an ID — `DE`, `US`| VAT inside it | £3.00 || Customer pays | **£17.99** |- Set `included_in_price: true`.+ Set `tax_inclusive: true` on the market.</Tab></Tabs>@@ -141,7 +138,7 @@ Rates name their country and state by **ISO code**, not by an ID — `DE`, `US`When building an order summary, add `additional_tax_total` only. `included_tax_total` is **already inside** the item prices — adding it counts the tax twice. This is the most common bug in a European storefront.</Warning>-Because prices are shown before anyone knows where the shopper lives, each [Market](/developer/core-concepts/markets) declares whether its prices are quoted with tax included. That's what lets a catalogue page show honest prices to a German visitor and a US visitor at the same time.+Because prices are shown before anyone knows where the shopper lives, each [Market](/developer/core-concepts/markets) declares whether its prices are quoted with tax included, and that holds for every customer of the market wherever they are. That's what lets a catalogue page show honest prices to a German visitor and a US visitor at the same time.## Tax lines@@ -219,6 +216,8 @@ A provider declares up front what it cannot do — no US local tax, no reverse cWhichever provider is in use, the result is the same: tax lines on the order, in the same shape. Your storefront code doesn't change.+Spree tells the provider whether the market's prices include tax: `estimate` and `estimate_replacement` receive it as `tax_inclusive:`. A provider passes it on to its service, such as a "tax included" flag on each line, and marks its tax lines `included` to match.+The provider also decides the tax given back on returns, claims and exchanges, and the refund pays exactly what it answers. Spree's own rates give back each returned unit's share of the tax the sale actually charged, so the customer gets back what they paid even if a rate has been edited since. An external service may calculate it itself instead, for example at the rates in force on the day of the sale. If it cannot be reached, the return is refused until it can, rather than refunding tax nobody worked out.If you are writing a provider, these are the calls Spree makes after the sale:diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdxindex 7a1edde9c8..25457685f7 100644--- a/docs/developer/upgrades/5.6-to-6.0.mdx+++ b/docs/developer/upgrades/5.6-to-6.0.mdx@@ -161,6 +161,16 @@ bundle exec rake spree:backfill_order_marketsA store without a market gets a default one covering its old checkout zone's countries (or its default country), and the checkout zone is cleared. Orders missing a market then get the store default — `market` is required on carts and orders in 6.0.+### Decide whether each market's prices include tax++```bash+bundle exec rake spree:markets:backfill_tax_inclusive+```++Tax rates no longer say whether they are included in the price; the market does, with `tax_inclusive` (see [Prices include tax per market](#prices-include-tax-per-market-not-per-rate)). This sets each market from the rates that cover its countries: all included in the price sets it to `true`, all added on top to `false`, and a market with no rates keeps its setting. A market whose rates mixed the two is left as it is and named in the output, for you to set by hand.++It reads each rate's old setting once and then clears it, so running it again later leaves your markets as they are.+### Fill in the stock level counters```bash@@ -573,6 +583,15 @@ now returns `nil` for an ID with another model's prefix, the same as`find_by_prefix_id`. Call `Spree::PrefixedId.decode_prefixed_id` if youreally need to decode any prefix.+## Prices include tax per market, not per rate++Whether a price includes tax is now the market's `tax_inclusive` setting ([Markets](/developer/core-concepts/markets#tax-behavior)). Before, each tax rate said so with `included_in_price`, and nothing read the market's flag.++- **Every customer of a market pays the price as entered.** In 5.x a store with a default tax zone adjusted prices for buyers outside it: its own tax came out of the price and the buyer's went in. That adjustment is gone, so those buyers now pay the price as entered, with their own country's tax inside it when the market's prices include tax. To charge some countries a different price, give them a market of their own with a price list.+- **The Admin API drops `included_in_price`** from tax rates: responses, request bodies, filters and sort. The dashboard's tax rate form and list drop it too. The column stays in the database until 6.1, for the upgrade step to read.+- **Tax providers receive `tax_inclusive:`** on `estimate` and `estimate_replacement`. A provider that names its keyword arguments must accept it.+- **Removed:** `Spree::VatPriceCalculation`, `Spree::Stock::Estimator#taxation_options_for`, `Spree::PriceRule#geographic?`, `Spree::Price#final_for_destination?`, and on `Spree::TaxRate` the `included_tax_amount_for`, `included_in_price` and `for_country` class methods and the `#included?` and `#additional?` methods. `TaxRate#adjustment_label` takes `included:`.+## Type values are short names, not class namesThe API no longer sends or accepts Ruby class names. Every value that used to name a class is now a short name (`Spree::CreditCard` becomes `credit_card`), so the API keeps the same shape whatever the server is built with. Records in the database are not touched.@@ -735,7 +754,7 @@ The single-currency accessors are gone from both `Variant` and `Product`:| `display_price`, `display_amount` | `price_in(currency).display_amount` || `compare_at_price=` | `set_price(currency, amount, compare_at_amount)` || `display_compare_at_price` | `price_in(currency).display_compare_at_amount` |-| `price_including_vat_for(opts)` | `price_in(currency).price_including_vat_for(opts)` |+| `price_including_vat_for(opts)` | `price_in(currency).amount` — prices are charged as entered || `has_default_price?` | `prices.base_prices.exists?(currency: currency)` |The `compare_at_price` **reader** (which resolves against `cost_currency`) is unchanged on both `Variant` and `Product` — only the writer is gone. So are the `price_in` / `amount_in` / `compare_at_amount_in` readers.@@ -986,6 +1005,7 @@ Before 6.0 a cart was an incomplete order, so extensions written for 5.x (paymen| `Fulfillment#ship`, `#ship!` | `Spree.fulfillment_fulfill_workflow.call(fulfillment:)` (`Spree::Fulfillments::Fulfill`) || `Fulfillment#shipped?`, `#can_ship?`, `#shipping_method`, `#add_shipping_method` | `#fulfilled?`, `#can_fulfill?`, `#delivery_method`, `#add_delivery_method` || `LineItem#target_shipment` | `#target_fulfillment` |+| `Price#price_including_vat_for`, `#compare_at_price_including_vat_for`, `#display_price_including_vat_for`, `#display_compare_at_price_including_vat_for` | `#price`, `#compare_at_price`, `#display_price`, `#display_compare_at_price` — prices are charged as entered for every buyer || `Order#create_proposed_shipments` / `#create_proposed_fulfillments` (Order and Cart) | `#rebuild_fulfillments!` || `#user`, `#user=`, `#user_id`, `#associate_user!` (Order and Cart) | `#customer`, `#customer=`, `#customer_id`, `#associate_customer!` || `#shipments`, `#set_shipments_cost`, `#ensure_updated_shipments`, `#display_shipment_total` (Order and Cart) | `#fulfillments`, `#set_fulfillments_cost`, `#ensure_updated_fulfillments`, `#display_delivery_total` |diff --git a/docs/plans/6.0-delivery-rate-provider.md b/docs/plans/6.0-delivery-rate-provider.mdindex 6935cbeaa5..0dccc600f2 100644--- a/docs/plans/6.0-delivery-rate-provider.md+++ b/docs/plans/6.0-delivery-rate-provider.md@@ -129,7 +129,7 @@ A carrier-backed DeliveryMethod is the carrier connection, not one service: `Del`Stock::Estimator` **stays**. It owns responsibilities no provider should re-implement per-seller:- method filtering (display target, zone `include?`, `calculator.available?`, currency match) — `estimator.rb:61-71`-- VAT gross-up via `Spree::VatPriceCalculation#gross_amount` — `estimator.rb:4, 38`+- VAT gross-up via `Spree::VatPriceCalculation#gross_amount` — `estimator.rb:4, 38` (removed 2026-10-16: delivery is charged as quoted, and the market decides whether its tax is inside — `6.0-tax-provider.md`)- tax rate resolution — `estimator.rb:54-59`- default selection + sorting — `estimator.rb:21-29`diff --git a/docs/plans/6.0-price-list-automatic-pricing.md b/docs/plans/6.0-price-list-automatic-pricing.mdindex bdd6ea6e5f..e09817607e 100644--- a/docs/plans/6.0-price-list-automatic-pricing.md+++ b/docs/plans/6.0-price-list-automatic-pricing.md@@ -76,7 +76,7 @@ maintain and no drift when base prices move.express "when they buy ten", because that is a property of the purchaseand not of the buyer. So the resolver consults an owned list's**contextual** rules (`PriceRule.contextual?` — a class predicate beside- `geographic?` and `superseded?`, deliberately not a constant, since+ `superseded?`, deliberately not a constant, sinceextensions register rule kinds of their own) and ignores its audiencerules. `VolumeRule` is the only contextual core kind. This is what makesthe headline case — a `VolumeRule` at `min_quantity: 10` plus −5% —diff --git a/docs/plans/6.0-tax-provider.md b/docs/plans/6.0-tax-provider.mdindex c0ab1c7734..b904aefe89 100644--- a/docs/plans/6.0-tax-provider.md+++ b/docs/plans/6.0-tax-provider.md@@ -10,12 +10,14 @@> **Contract refinement (2026-08-05):** the provider contract was reworked after the community review on spree/spree#14056, with every concern verified against primary sources (EN 16931 / VAT Directive / VIES), the major provider APIs (Avalara, Stripe Tax, TaxJar, Vertex) and platform practice (Medusa, Saleor, commercetools, Shopify, Magento, Odoo). Headlines: tax results carry a **taxability reason**, not just an amount; buyer tax identity becomes a first-class **`Spree::TaxIdentifier`** model with an order-time snapshot; exemption is a **typed estimate input** (the boolean `exempt?` is removed); the **effective date** is an explicit input; providers declare **capability limits** honestly. See Key Decisions.+> **The market decides tax inclusion (2026-10-16, V-3662):** whether a price includes tax is `Market#tax_inclusive` alone. Spree's own tables read it and every provider receives it as `tax_inclusive:` on `estimate` and `estimate_replacement`; `TaxRate#included_in_price` is retired (column dropped in 6.1), and the 2026-08-11 cross-border restatement is removed, so every customer pays the price as entered. See the cross-border Key Decision, Phase 8 and decisions.md.+> **Post-sale tax (2026-10-01, V-3725):** returns, claims and exchanges now give back the tax the customer paid, and the provider decides that figure. The contract gains `estimate_refund` (credit rows on return, claim and exchange lines; `Internal` answers with the recorded share of the sale's rows), `estimate_replacement` (an exchange's replacement taxed as a new sale) and `commit_replacement`. `refund` keeps its signature and files what the credit rows hold. Post-sale rows hang off the order but never count towards its totals. See "Post-sale tax" below and decisions.md 2026-10-01.**Target:** Spree 6.0**Depends on:** Split Adjustments (6.0-6.1-split-adjustments.md — shipped; provides TaxLine). Phase 7 pulls the Company tree forward out of `6.0-channels-catalogs-b2b.md` rather than waiting on it — that plan keeps Catalog, per-company pricing and product visibility, and inherits the models this phase ships.**Author:** Damian + Claude-**Last updated:** 2026-10-01+**Last updated:** 2026-10-16## Summary@@ -50,7 +52,7 @@ The seam itself is live on `main`: providers are the only sanctioned writers of| `TaxRate` model | `core/app/models/spree/tax_rate.rb` | Stored rate %, zone, tax category. `adjust()` was the entry point. || `TaxRate.match(zone)` | TaxRate class method | Found rates whose zone includes the order's tax zone || `Calculator::DefaultTax` | `core/app/models/spree/calculator/` | Computed tax amount for line items, shipments, shipping rates |-| `VatPriceCalculation` | `core/app/models/concerns/` | Handled included-in-price tax math |+| `VatPriceCalculation` | `core/app/models/concerns/` | Handled included-in-price tax math (removed 2026-10-16) || `TaxRate.store_pre_tax_amount` | TaxRate class method | Computed and stored pre-tax amounts for VAT calculations || `Adjuster::Tax` | `core/app/models/spree/adjustable/adjuster/` | Orchestrated tax adjustment updates during recalculation || `TaxCategory` | `core/app/models/spree/tax_category.rb` | Groups products/variants by tax type (unchanged) |@@ -127,7 +129,7 @@ Carts::RecalculateTotals#perform (single totals seam, cart + order twins)### Provider replaces TaxRate.adjust entirely- **`TaxRate.adjust` is removed.** The provider is the only entry point for tax calculation and the only sanctioned TaxLine writer. No `AdjustmentSource`, no `CalculatedAdjustments` concern on TaxRate, no `Calculator::DefaultTax`.-- **`TaxRate` stays as pure configuration** (rate %, zone until Phase 5, tax category, included_in_price) — no behavior.+- **`TaxRate` stays as pure configuration** (rate %, zone until Phase 5, tax category) — no behavior. Whether its tax sits inside a price is the market's `tax_inclusive` since 2026-10-16, not the rate's `included_in_price`.### Provider contract: estimate/commit/void/refund with explicit dates@@ -481,43 +483,32 @@ which match nothing it owns — widening the claim over every line it holds.**Hook boundary:** the `set_tax_line_context` hook is NOT the exemption channel. Typed inputs — exemptions from `tax_resolve_exemptions_service`, the identifier from `#resolved_tax_identifier`, the tax date from the caller — arrive as named `estimate` parameters: declared shapes, one implementation each, no deep-merge collisions. The hook remains for untyped provider-specific extras only (riding into `TaxLine.data` / provider requests as the `context:` parameter); its doc comment — which currently names "exemption certificates, customer tax IDs" as its payload — must be corrected before the 6.0 hook-contract freeze.-### Cross-border pricing: derive net-fixed, unless the merchant priced that geography (2026-08-11)+### Cross-border pricing: every price is charged as entered (2026-08-11, reversed 2026-10-16)A tax-inclusive price is expressed in *some* country's VAT. When the buyer is in another one, theplatform must decide whether the **shopper's price** stays put and the merchant's margin moves, or-the **merchant's net** stays put and the price moves. Both are coherent; the industry ships both and-names the first "price consistency".--Spree takes the two-tier answer, which is Shopify's:--1. **A price the merchant set for a geography is final** — charged exactly as entered, never- restated. `Spree::Price#final_for_destination?` is true when the winning list carries a rule that- answers `geographic?` (`MarketRule`, `ZoneRule`) *and* that rule is why the list won — see the- `match_policy` condition in step 2 of the implementation below. This is Shopify's carve-out:- fixed per-country prices receive no adjustment.-2. **Everything else derives net-fixed** — the home rate out, the destination's on, via- `VatPriceCalculation`. The merchant's take is preserved; the gross moves, cents and all.--**Why the carve-out keys on the rule and not on `price_list_id`.** A volume or customer-group list-price was set for a quantity or a group, not for a country — restating it protects the same margin a-base price's restatement protects. Only a rule that names a geography licenses the claim "this-figure is already correct for that geography."--**Why net-fixed is the default.** Four of the platforms surveyed derive this way by default-(WooCommerce, Magento/Adobe, Shopify, Vendure), and the alternative silently moves the merchant's-margin: with the German 19% price charged into France's 20%, the net falls 84.03 → 83.33 with nothing-on the order recording that the merchant absorbed it. Magento's own documentation states the-consequence of enabling consistency — "your profit margin changes by tax rate… The store absorbs any-difference between domestic and foreign VAT rates."--**Restatement is an Internal-provider capability, not a platform one.** `VatPriceCalculation` derives-both halves from `TaxRate` rows, so it can only work where those rows are the truth. An absent row is-ambiguous — *no tax due* or *computed by an engine* — and it reads as the former, which turns every-foreign destination on an external-provider market into an apparent zero-rated export. So-restatement runs for Internal and is skipped elsewhere, and a market on an external engine states its-destination prices through a geo-scoped price list instead. Shopify reached the same place from the-other direction: their dynamic tax-inclusive pricing reads a standard-rate table and is explicitly-incompatible with AvaTax.+the **merchant's net** stays put and the price moves. Both are coherent; the industry ships both.++**Spree keeps the shopper's price (2026-10-16, V-3662).** `Market#tax_inclusive` is the only setting+for whether prices include tax: on, every customer of the market pays the price as entered with+their own country's tax inside it; off, tax is added at checkout. Tax rates hold a percentage and a+jurisdiction, nothing else — `TaxRate#included_in_price` is retired. Spree's own tables read the+setting through `Purchase::Taxation#tax_inclusive?`, and every provider receives it as+`tax_inclusive:`. This is Shopify's "Show as included" and "Show as line item".++**The 2026-08-11 rule is gone.** It derived net-fixed through `VatPriceCalculation` — the home rate+out of the price, the destination's in — except for a price on a list narrowed by geography+(`PriceRule#geographic?`, `Price#final_for_destination?`). V-3662 showed its cost: a US store's+Germany market priced 100.00 charged 119.00 at checkout, because the US's 0% came out and 19% went+in. It also worked only on the Internal provider, since an external engine keeps no rows to read+both rates from; it showed a market of several countries the main country's price until the address+was known; and it turned round prices into odd ones. A merchant who wants a different price in some+countries gives them a market of their own with a price list, and one market applies one convention+to all its countries.++**Restatement may return in 6.1** if merchants ask for it: as an Internal-provider option that reads+the storefront's country before an address exists, or as a country rule on price lists, which works+with every engine.### Provider is per-Market — selection, not construction@@ -1021,8 +1012,8 @@ module Spreetax_rate: rate, # internal rows keep the FK — external ones leave it nilamount: amount,rate: rate.amount, # snapshot: survives a rate edit or deletion- label: rate.adjustment_label,- included: rate.included_in_price,+ label: rate.adjustment_label(included: tax_inclusive),+ included: tax_inclusive, # the market's setting (2026-10-16), not the rate'sprovider_id: 'internal',taxability_reason: reason, # 'standard_rated' / 'zero_rated' / 'customer_exempt'country_code: rate.country_code,@@ -1141,7 +1132,7 @@ The **admin** side adds `validation_status`, `validated_at`, `validation_evidenc**Tax rates.** `/admin/tax_rates` — full CRUD, admin-only (rates are back-office configuration; the storefront never sees them). This plan owns building them even though `6.0-admin-api.md` carries the checkboxes, for a blunt reason: **TaxRate rows are the Internal provider's entire configuration**, so without these endpoints the default tax engine cannot be set up or inspected through the API at all, and nothing about its behavior can be verified outside a console or a spec. Tax categories already have their endpoints; rates are the missing half.-Serializer fields: `name`, `amount` (plus `amount_percentage`, the virtual the admin forms use), `included_in_price`, `show_rate_in_label`, `tax_category_id`, `store_id`, `metadata`, timestamps and `deleted_at` (the model is paranoid). The jurisdiction field follows the schema of the moment — `zone_id` until Phase 5, `country_code`/`state_code` after it, which is the one place these endpoints get reworked. `whitelisted_ransackable_attributes` already covers `amount`, `tax_category_id`, `included_in_price` and `name`, so filtering comes free; Phase 5 swaps `zone_id` for the country and state codes there too.+Serializer fields: `name`, `amount` (plus `amount_percentage`, the virtual the admin forms use), `show_rate_in_label` (`included_in_price` removed 2026-10-16), `tax_category_id`, `store_id`, `metadata`, timestamps and `deleted_at` (the model is paranoid). The jurisdiction field follows the schema of the moment — `zone_id` until Phase 5, `country_code`/`state_code` after it, which is the one place these endpoints get reworked. `whitelisted_ransackable_attributes` already covers `amount`, `tax_category_id`, `included_in_price` and `name`, so filtering comes free; Phase 5 swaps `zone_id` for the country and state codes there too.**Provider discovery and selection.**@@ -1437,6 +1428,8 @@ managing them in the admin UI belongs to the B2B release.### Phase 8: cross-border pricing with tax-inclusive prices+> **Reversed 2026-10-16 (V-3662):** restatement is removed — every customer pays the price as entered (see the cross-border Key Decision). Work items 1 and 3 below still stand: a cart prices from its own market, and a destination change persists the re-price, which price lists narrowed by market still need. Items 2 and 4, and the restatement cases in 5, went with it.+**Ships in 6.0.** Three defects found by a live pass against a running server (2026-08-11), all inthe same seam: what a customer is charged when the destination's VAT rate differs from the homezone's. None of them is visible in a single-country store, which is why the engine suites never@@ -1553,11 +1546,10 @@ manifest, so every install arriving at 6.1 has run them.3. **Drop the vestigial `tax_rates` slot from the `SpreeCalculators` struct.** Tax has had nocalculator since `Calculator::DefaultTax` was removed; the slot is a public-ish constant, soit gets a boundary rather than a silent edit.-4. **Decide `Market#tax_inclusive`.** A dead boolean with no reader in `app/` that the API still- serializes and permits. 6.0 left it alone deliberately — Internal derives- inclusive-vs-additive per rate from `TaxRate#included_in_price`, which is finer-grained than- a market-wide flag. Either wire it for external providers or drop it together with its API- fields; it should not survive a third release undecided.+4. **Drop `spree_tax_rates.included_in_price`.** Decided 2026-10-16: `Market#tax_inclusive` is the+ one setting, read by Internal and passed to every provider, and the rate's flag left the API and+ the dashboard. The column stays through 6.0 only because `spree:markets:backfill_tax_inclusive`+ reads it after `db:migrate`; drop it once every install has run that step.## Constraints on Current Work@@ -1565,9 +1557,9 @@ manifest, so every install arriving at 6.1 has run them.carry the owner's own `market` alongside its `country`. Anything that prices a cart line from therequest context makes the same cart price differently between two requests — measured, and itpersists. Catalogue requests keep the `Spree::Current` fallback; they have no owner to read.-- **A new `PriceRule` subclass must answer `geographic?`.** The default is `false`; a rule that- narrows by geography returns `true` and thereby exempts its list's prices from VAT restatement.- Getting this wrong on a new rule type silently changes what customers are charged abroad.+- **Whether a price includes tax is the market's.** Read it through the owner's `tax_inclusive?` or+ the provider's `tax_inclusive:` input, never from a tax rate, and never adjust a price for the+ buyer's country: every customer of a market pays the price as entered.- **Re-pricing on a destination change must stay behind the drift guard.**`Carts::Complete#verify_expected_total` returning `cart_changed` is what makes a mid-checkout pricemovement disclosable rather than silent. Don't weaken it, and don't add re-pricing paths that skip@@ -1600,8 +1592,8 @@ manifest, so every install arriving at 6.1 has run them.**Still open, and now sequenced after Phase 7** (2026-08-07 — it is one of the two remaining items on PR #14410). Phases 3–5 neither need nor are blocked by an answer, and the only knock-on is that a market pointed at an external provider shows no tax on its delivery options while checkout charges the provider's — a display defect, not a collection one, since the money still comes from the provider's TaxLines. Phase 5 re-pointed the rate matching mechanically. Dropping tax from the option labels entirely stays on the table as an outcome, not just a fallback; whichever way it lands, it should be settled with `6.0-delivery-rate-provider.md`, which owns `DeliveryRate` enrichment.Resolved (previously open):-- **Cross-border restatement scope (2026-08-11)** — derive net-fixed by default; never restate a- price whose winning price list carries a `geographic?` rule. Settled with the two-tier decision in+- **Cross-border restatement scope (2026-08-11, reversed 2026-10-16)** — derive net-fixed by default; never restate a+ price whose winning price list carries a `geographic?` rule. Reversed by V-3662: restatement is removed and every price is charged as entered. Settled with the two-tier decision inKey Decisions after surveying seven platforms; the alternative rules considered (any`price_list_id`, an explicit `prices_are_final` column) were rejected for letting a non-geographiclist erode margin, and for adding a merchant-facing concept where a rule already states the intent.diff --git a/docs/plans/6.0-third-party-pricing-inventory.md b/docs/plans/6.0-third-party-pricing-inventory.mdindex 4252e8419f..c4a1ec2af0 100644--- a/docs/plans/6.0-third-party-pricing-inventory.md+++ b/docs/plans/6.0-third-party-pricing-inventory.md@@ -134,7 +134,7 @@ end- Selection: Store preference `pricing_provider` (string, validated against the registry on change, default `internal`) — decision 12.- `Variant#price_for(context)` becomes: `provider = context.store.pricing_provider_instance; provider.handles?(context) ? provider.price_for(context) : Internal.new.price_for(context)`, with the cache wrapper (`Rails.cache.fetch(context.cache_key, expires_in: provider.cache_ttl)`) applied only for providers with a `cache_ttl`. Cached values are the price's attributes, rehydrated into a `readonly!` `Spree::Price` — never a marshalled AR object.- The provider is given the full `Pricing::Context` (variant, currency, store, country, market, channel, user, quantity, date, order) — a contract-pricing provider reads `context.user` → company → external reference for the ERP account, and `context.quantity` for breaks.-- Returned prices for tax-inclusive markets go through the same `price_including_vat_for` restatement as catalog prices; a provider that returns a destination-priced amount marks it (`price.geographic = true`, transient) so the restatement rule from tax-provider Phase 8 applies unchanged.+- Returned prices for tax-inclusive markets go through the same `price_including_vat_for` restatement as catalog prices; a provider that returns a destination-priced amount marks it (`price.geographic = true`, transient) so the restatement rule from tax-provider Phase 8 applies unchanged. (Restatement was removed 2026-10-16: a provider's price is charged as entered, like a catalog price.)- **Call-site refactor** (decision 7): a new `Spree::Carts::PriceItems` service (Tier 1) owns "for each of these line items, resolve the price and write `price` + `price_list_id` + `price_source`". `AddItem` and `UpsertItems` call it from an `external_step` before the item write, and `Complete#recalculate_in_lock` re-prices under `strict` policy so a stale cached contract price cannot complete. `money_frozen?` orders are never re-priced — except for a line being *added* to a placed order, which still needs its price (an admin amendment must not bill a contract customer at list).**Superseded by what shipped (see deviation 6):** `Recalculate` gained no `reprice_items` step — `Cart#recalculate_for_address_change!` is the address-change path and batches through `PriceItems` directly, so there is exactly one repricing point per flow. And `LineItem#recalculate_price` / `#update_price` are thin delegates rather than deprecated shells; `copy_price` reaches only the **local** catalog, never a provider, so no validation callback can put a network call inside a save.diff --git a/docs/plans/decisions.md b/docs/plans/decisions.mdindex 4d7b7d1257..216c2e1b83 100644--- a/docs/plans/decisions.md+++ b/docs/plans/decisions.md@@ -18,6 +18,16 @@**Plan:** `6.0-tax-provider.md`.+## 2026-10-16: The market decides whether prices include tax, and prices are no longer adjusted for buyers abroad (V-3662, reverses 2026-08-11)++**Context:** A store whose home country is the US sold into a Eurozone market marked tax-inclusive. A €527.99 book shipped to Berlin was charged €564.95: the 2026-08-11 rule took the US's 0% out of the price and put Germany's 7% in, so the product page and checkout disagreed. Whether a price includes tax was spread over three places: `TaxRate#included_in_price`, which Spree's own tax tables read; `Market#tax_inclusive`, which the API and dashboard exposed but no code read; and the restatement, which assumed every price included the home country's tax. A first fix for #14833 added a per-market `tax_display` and a main country per market; review rejected a second setting beside the unused one.++**Decision:** `Market#tax_inclusive` is the one setting. On, every customer of the market pays the price as entered, with their own country's tax inside it; off, tax is added at checkout. Spree's own tax tables read it through `Purchase::Taxation#tax_inclusive?` (with no market, the store's default market answers), and every provider receives it as `tax_inclusive:` on `estimate` and `estimate_replacement`. Refunds keep the `included` flag the sale's tax lines recorded, so editing a market never changes a placed order. `TaxRate#included_in_price` leaves the Admin API, the SDK and the dashboard; the column stays until 6.1 for `spree:markets:backfill_tax_inclusive`, which sets each market from the rates covering its countries (all included sets true, all added on top sets false, a mix is left unchanged and reported). It reads each rate's flag once and clears it, because every upgrade re-runs every step, and new rates leave the flag empty. Restatement is removed, with `VatPriceCalculation`, `PriceRule#geographic?` and `Price#final_for_destination?`: it ran only on the Internal provider, showed a multi-country market the main country's price until checkout, and broke round prices. Without it the home country prices nothing, so markets keep no main country of their own. Commission tax reads every matching rate, since a commission's tax is added on top whatever a market does.++**Consequences:** A merchant who wants a different price in some countries gives them a market of their own with a price list, and one market cannot mix conventions by country. A 5.x store with a default tax zone, and a store on the 6.0 release candidates, charges buyers abroad the price as entered after upgrading, which the upgrade guide says. Commission VAT in an EU store whose rates were all marked included now uses the real rate rather than the store default. A provider that names its keyword arguments must accept `tax_inclusive:`. A business buyer with a valid tax number pays the price as entered in an inclusive market; whether they should pay it without tax stays open. Restatement can return in 6.1, reading the storefront's country, or as a country rule on price lists, if merchants ask for it.++**Plans amended:** `6.0-tax-provider.md` (the cross-border Key Decision, Phase 8, the Phase 9 `tax_inclusive` item and the Constraints on Current Work).+## 2026-10-10: One upload endpoint, store-owned blobs, and `<slot>_signed_id` everywhere**Context:** Files reached Spree through `/direct_uploads`, which copied Active Storage's nested request and minted references that never expired, and nothing recorded which store a blob belonged to. Endpoints that took those references named them seven different ways.diff --git a/docs/user/settings/markets.mdx b/docs/user/settings/markets.mdxindex a9c7f6f4c3..17c1621a72 100644--- a/docs/user/settings/markets.mdx+++ b/docs/user/settings/markets.mdx@@ -35,13 +35,26 @@ Click **Add market**.- **Supported locales** - Additional languages shoppers can switch to. The default locale is always included.- **Countries** - The countries this market covers. Search for each one and add it.- **Tax engine** - Which engine calculates tax for orders in this market. Leave this as it is unless another engine has been installed for your store.-- **Tax-inclusive pricing** - Display prices with tax included. Common in EU markets.+- **Prices include tax** - Turn this on when the prices you enter for this market already include tax, as is usual in Europe. Leave it off when tax is added at checkout, as is usual in North America. See below.- **Default market** - Shoppers without a known country see this market. Only one can be default per store.Click **Create market** when you are done.<Warning>Each country can belong to at most one market per store. A country already claimed by another market cannot be added to a second one, so plan your coverage before creating several markets.</Warning>+### Prices include tax, or tax added at checkout++This switch is the difference between how European and North American stores usually work, and getting it wrong misprices everything in the market. Take a product priced at 120, with a 20% tax rate:++| Prices include tax | The customer pays |+|---|---|+| **On** | 120, of which 20 is tax |+| **Off** | 144: the 120 price plus 24 tax at checkout |++Every customer of the market pays the price you entered, wherever they are. With the switch on, a customer in a country with a different rate pays the same price, with their own country's tax inside it.++<Note>To charge customers in some countries a different price, put those countries in a market of their own and give it a [<u>price list</u>](/user/pricing/price-lists) with a market rule.</Note>+### What the built-in tax engine does not calculateSpree's built-in tax engine handles the rates you configure per country or state. Four things it does not do are printed under the **Tax engine** chooser, and each one can mean collecting the wrong amount of tax:diff --git a/docs/user/settings/tax-rates.mdx b/docs/user/settings/tax-rates.mdxindex 2964c73550..9db870e578 100644--- a/docs/user/settings/tax-rates.mdx+++ b/docs/user/settings/tax-rates.mdx@@ -15,14 +15,13 @@ To manage tax rates, navigate to **Settings → Taxes**, under the **Selling** g## Reviewing Your Tax Rates-+Each row shows:- **Name** - What the rate is called.- **Rate** - The percentage charged.- **Applies to** - The country, and the state where one is set.-- **Included in price** - Whether displayed prices already contain this tax.## How to Create a Tax Rate@@ -35,21 +34,13 @@ Click **Add tax rate**.- **Tax category** - Which products this rate taxes. Only goods carrying this category are affected.- **Country** - Where the rate applies. Leave it empty to tax every country.- **State** - Narrows the rate to one state. This field only appears once you pick a country that has states.-- **Included in price** - Prices already carry this tax, so it is backed out of the displayed price rather than added at checkout.- **Show rate in the tax label** - Adds the percentage to the tax line the customer sees, so it reads "VAT (20%)" rather than "VAT".Click **Create tax rate**.<Warning>A rate that names no country taxes every country. Leaving **Country** empty is occasionally what you want, but more often it is an oversight that taxes customers who should not be charged.</Warning>-### Included in price, or added at checkout--This switch is the difference between how European and North American stores usually work, and getting it wrong misprices everything on the affected goods.--- **On** suits regions where advertised prices include tax. A product shown at 120 with a 20% rate is treated as 100 plus 20 tax, and the customer pays 120.-- **Off** suits regions where tax is added at the end. A product shown at 120 with a 20% rate becomes 144 at checkout.--<Note>Whether a market displays prices with tax included is set on the market itself. Set **Tax-inclusive pricing** on the [<u>market</u>](/user/settings/markets) and **Included in price** on its rates to match, or displayed prices and charged tax will disagree.</Note>+<Note>Whether your prices already include these taxes, or the tax is added at checkout, is set on each [<u>market</u>](/user/settings/markets) with **Prices include tax**, not on the rate.</Note>## How to Edit a Tax Rate@@ -66,5 +57,5 @@ Open the row menu and choose **Delete**.## Further Reading- [<u>Tax Categories</u>](/user/settings/tax-categories) - The groupings a rate applies to-- [<u>Markets</u>](/user/settings/markets) - Where tax-inclusive pricing and the tax engine are set+- [<u>Markets</u>](/user/settings/markets) - Where **Prices include tax** and the tax engine are set- [<u>Orders</u>](/user/orders/orders) - How tax appears in an order's summarydiff --git a/packages/admin-sdk/examples/tax-rates/create.ts b/packages/admin-sdk/examples/tax-rates/create.tsindex 6f25ce4483..e0092f1368 100644--- a/packages/admin-sdk/examples/tax-rates/create.ts+++ b/packages/admin-sdk/examples/tax-rates/create.ts@@ -12,7 +12,6 @@ const taxRate = await client.taxRates.create({rate_percent: '19',country_code: 'DE',tax_category_id: 'txc_UkLWZg9DAJ',- included_in_price: true,})// endregion:examplediff --git a/packages/admin-sdk/src/types/filters.generated.ts b/packages/admin-sdk/src/types/filters.generated.tsindex d4da21af53..6e03c20e5e 100644--- a/packages/admin-sdk/src/types/filters.generated.ts+++ b/packages/admin-sdk/src/types/filters.generated.ts@@ -461,7 +461,6 @@ export type TaxLineFields = Filter.TextFilters<'country_code' | 'provider_id' |export type TaxRateFields = Filter.RangeFilters<'amount' | 'created_at' | 'rate' | 'updated_at'>& Filter.TextFilters<'country_code' | 'name' | 'state_code'>& Filter.IdFilters<'id' | 'tax_category_id'>- & Filter.BooleanFilters<'included_in_price'>export type VariantFields = Filter.IdFilters<'carton_package_type_id' | 'id' | 'product_id'>& Filter.RangeFilters<'carton_weight' | 'cost_price' | 'created_at' | 'deleted_at' | 'depth' | 'discontinue_on' | 'height' | 'updated_at' | 'weight' | 'width'>@@ -2590,7 +2589,7 @@ export type TaxRateFilters = TaxRateFields& Filter.OrFilters& TaxRateFilterExtensions-export type TaxRateSort = Filter.SortKey<'amount' | 'country_code' | 'created_at' | 'id' | 'included_in_price' | 'name' | 'rate' | 'state_code' | 'tax_category_id' | 'updated_at' | (keyof TaxRateSortExtensions & string)>+export type TaxRateSort = Filter.SortKey<'amount' | 'country_code' | 'created_at' | 'id' | 'name' | 'rate' | 'state_code' | 'tax_category_id' | 'updated_at' | (keyof TaxRateSortExtensions & string)>/*** Filters your app adds to Variant lists. Generate them with `spree filters types`,diff --git a/packages/admin-sdk/src/types/generated/TaxRate.ts b/packages/admin-sdk/src/types/generated/TaxRate.tsindex 6fbe2d5461..3144adca83 100644--- a/packages/admin-sdk/src/types/generated/TaxRate.ts+++ b/packages/admin-sdk/src/types/generated/TaxRate.ts@@ -1,4 +1,4 @@-// Typelizer digest 6fbae478d012c8c4659d3afd45ef27de+// Typelizer digest 4fc26e9bb7fcabfd6c2700c2e67365e2//// DO NOT MODIFY: This file was automatically generated by Typelizer.import type {CountryCode} from '@/types'@@ -6,7 +6,6 @@ import type {CountryCode} from '@/types'interface TaxRate {id: string;name: string;- included_in_price: boolean;show_rate_in_label: boolean;metadata: Record<string, unknown> | null;created_at: string;diff --git a/packages/admin-sdk/src/types/params/MarketCreateParams.ts b/packages/admin-sdk/src/types/params/MarketCreateParams.tsindex d26afe8696..08d1a5c7cd 100644--- a/packages/admin-sdk/src/types/params/MarketCreateParams.ts+++ b/packages/admin-sdk/src/types/params/MarketCreateParams.ts@@ -11,7 +11,10 @@ export type MarketCreateParams = {currency: CurrencyCode/** Locale used as the market default. Always part of `supported_locales`. */default_locale: LocaleCode- /** Display prices with tax included. */+ /**+ * Whether the prices entered for this market include tax. True charges every customer the price+ * as entered, with their tax inside it; false adds tax at checkout.+ */tax_inclusive?: boolean/*** Shorthand of the tax engine that prices this market, from the tax providers endpoint. Null usesdiff --git a/packages/admin-sdk/src/types/params/MarketUpdateParams.ts b/packages/admin-sdk/src/types/params/MarketUpdateParams.tsindex c433443e20..5a4e62f17f 100644--- a/packages/admin-sdk/src/types/params/MarketUpdateParams.ts+++ b/packages/admin-sdk/src/types/params/MarketUpdateParams.ts@@ -11,7 +11,10 @@ export type MarketUpdateParams = {currency?: CurrencyCode/** Locale used as the market default. Always part of `supported_locales`. */default_locale?: LocaleCode- /** Display prices with tax included. */+ /**+ * Whether the prices entered for this market include tax. True charges every customer the price+ * as entered, with their tax inside it; false adds tax at checkout.+ */tax_inclusive?: boolean/*** Shorthand of the tax engine that prices this market, from the tax providers endpoint. Null usesdiff --git a/packages/admin-sdk/src/types/params/TaxRateCreateParams.ts b/packages/admin-sdk/src/types/params/TaxRateCreateParams.tsindex 04a98d58a1..88a34791e6 100644--- a/packages/admin-sdk/src/types/params/TaxRateCreateParams.ts+++ b/packages/admin-sdk/src/types/params/TaxRateCreateParams.ts@@ -9,7 +9,6 @@ export type TaxRateCreateParams = {rate?: string/** The rate as a percentage. */rate_percent?: string- included_in_price?: booleanshow_rate_in_label?: booleantax_category_id: string/** ISO country code. A rate naming no country taxes everywhere. */diff --git a/packages/admin-sdk/src/types/params/TaxRateUpdateParams.ts b/packages/admin-sdk/src/types/params/TaxRateUpdateParams.tsindex 69b08e2c7a..7e0ad5016c 100644--- a/packages/admin-sdk/src/types/params/TaxRateUpdateParams.ts+++ b/packages/admin-sdk/src/types/params/TaxRateUpdateParams.ts@@ -9,7 +9,6 @@ export type TaxRateUpdateParams = {rate?: string/** The rate as a percentage. */rate_percent?: string- included_in_price?: booleanshow_rate_in_label?: booleantax_category_id?: string/** ISO country code. A rate naming no country taxes everywhere. */diff --git a/packages/admin-sdk/src/zod/generated/TaxRate.ts b/packages/admin-sdk/src/zod/generated/TaxRate.tsindex fbdb1e3783..58add8d5c5 100644--- a/packages/admin-sdk/src/zod/generated/TaxRate.ts+++ b/packages/admin-sdk/src/zod/generated/TaxRate.ts@@ -4,7 +4,6 @@ import { z } from 'zod';export const TaxRateSchema = z.object({id: z.string(),name: z.string(),- included_in_price: z.boolean(),show_rate_in_label: z.boolean(),metadata: z.record(z.string(), z.unknown()).nullable(),created_at: z.string(),diff --git a/packages/admin-sdk/tests/tax-rates.test.ts b/packages/admin-sdk/tests/tax-rates.test.tsindex 3cf9fa5e8c..5a97bcaeea 100644--- a/packages/admin-sdk/tests/tax-rates.test.ts+++ b/packages/admin-sdk/tests/tax-rates.test.ts@@ -12,7 +12,6 @@ const sampleTaxRate = {amount_percentage: 19.0,country_code: 'DE',state_code: null,- included_in_price: true,show_rate_in_label: true,created_at: '2026-08-01T00:00:00Z',updated_at: '2026-08-01T00:00:00Z',diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.jsonindex c2d1092505..6a8ced093e 100644--- a/packages/dashboard/src/locales/ar.json+++ b/packages/dashboard/src/locales/ar.json@@ -1447,8 +1447,8 @@"label": "اللغات المدعومة"},"tax_inclusive": {- "help": "عرض الأسعار مع الضريبة. شائع في أسواق الاتحاد الأوروبي.",- "label": "تسعير شامل الضريبة"+ "help": "مفعّل: يدفع العملاء السعر الذي تُدخله وتكون الضريبة مشمولة فيه. معطّل: تُضاف الضريبة عند الدفع.",+ "label": "الأسعار تشمل الضريبة"},"tax_provider": {"help": "ما يحسب الضريبة لطلبات هذا السوق.",@@ -2239,11 +2239,6 @@"country_code": {"help": "اتركه فارغاً لفرض الضريبة على كل الدول."},- "included_in_price": {- "help": "الأسعار تتضمن هذه الضريبة أصلاً، لذا تُستخرج منها بدلاً من أن تُضاف إليها.",- "label": "مشمولة في السعر",- "short": "مشمولة"- },"jurisdiction": {"label": "تسري على"},diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.jsonindex 1462f2c0ef..306242490e 100644--- a/packages/dashboard/src/locales/de.json+++ b/packages/dashboard/src/locales/de.json@@ -1429,8 +1429,8 @@"label": "Unterstützte Sprachen"},"tax_inclusive": {- "help": "Preise mit enthaltener Steuer anzeigen. In EU-Märkten üblich.",- "label": "Preise inklusive Steuer"+ "help": "An: Kunden zahlen den eingegebenen Preis, die Steuer ist darin enthalten. Aus: Die Steuer wird an der Kasse hinzugefügt.",+ "label": "Preise enthalten Steuern"},"tax_provider": {"help": "Womit die Steuer für Bestellungen in diesem Markt berechnet wird.",@@ -2221,11 +2221,6 @@"country_code": {"help": "Leer lassen, um jedes Land zu besteuern."},- "included_in_price": {- "help": "Die Preise enthalten diese Steuer bereits, sie wird herausgerechnet statt aufgeschlagen.",- "label": "Im Preis enthalten",- "short": "Enthalten"- },"jurisdiction": {"label": "Gilt für"},diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex 35b6a598ff..9c8bab085b 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -1429,8 +1429,8 @@"label": "Supported locales"},"tax_inclusive": {- "help": "Display prices with tax included. Common in EU markets.",- "label": "Tax-inclusive pricing"+ "help": "On: customers pay the price you enter, with tax inside it. Off: tax is added at checkout.",+ "label": "Prices include tax"},"tax_provider": {"help": "Which engine calculates tax for orders in this market.",@@ -2221,11 +2221,6 @@"country_code": {"help": "Leave empty to tax every country."},- "included_in_price": {- "help": "Prices already carry this tax, so it is backed out rather than added.",- "label": "Included in price",- "short": "Included"- },"jurisdiction": {"label": "Applies to"},diff --git a/packages/dashboard/src/locales/es.json b/packages/dashboard/src/locales/es.jsonindex eb7cf2d345..cdfb864126 100644--- a/packages/dashboard/src/locales/es.json+++ b/packages/dashboard/src/locales/es.json@@ -1525,8 +1525,8 @@"label": "Idiomas admitidos"},"tax_inclusive": {- "help": "Mostrar los precios con impuestos incluidos. Común en mercados de la UE.",- "label": "Precios con impuestos incluidos"+ "help": "Activado: los clientes pagan el precio que introduces, con los impuestos incluidos. Desactivado: los impuestos se añaden al finalizar la compra.",+ "label": "Los precios incluyen impuestos"},"tax_provider": {"help": "Qué motor calcula los impuestos de los pedidos de este mercado.",@@ -2317,11 +2317,6 @@"country_code": {"help": "Dejalo vacío para cobrar impuestos en todos los países."},- "included_in_price": {- "help": "Los precios ya incluyen este impuesto, así que se descuenta en lugar de sumarse.",- "label": "Incluido en el precio",- "short": "Incluido"- },"jurisdiction": {"label": "Aplica a"},diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.jsonindex 1647a419d6..bf61591dd6 100644--- a/packages/dashboard/src/locales/fr.json+++ b/packages/dashboard/src/locales/fr.json@@ -1429,8 +1429,8 @@"label": "Langues prises en charge"},"tax_inclusive": {- "help": "Afficher les prix taxes comprises. Courant sur les marchés de l'UE.",- "label": "Prix taxes comprises"+ "help": "Activé : les clients paient le prix saisi, taxes incluses. Désactivé : les taxes sont ajoutées lors du paiement.",+ "label": "Les prix incluent les taxes"},"tax_provider": {"help": "Ce qui calcule la taxe pour les commandes de ce marché.",@@ -2221,11 +2221,6 @@"country_code": {"help": "Laissez vide pour taxer tous les pays."},- "included_in_price": {- "help": "Les prix contiennent déjà cette taxe, elle est déduite au lieu d'être ajoutée.",- "label": "Incluse dans le prix",- "short": "Incluse"- },"jurisdiction": {"label": "S'applique à"},diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.jsonindex 439bf4ec07..e2c3ba225a 100644--- a/packages/dashboard/src/locales/pl.json+++ b/packages/dashboard/src/locales/pl.json@@ -1447,8 +1447,8 @@"label": "Obsługiwane ustawienia regionalne"},"tax_inclusive": {- "help": "Wyświetlaj ceny z uwzględnionym podatkiem. Powszechne na rynkach UE.",- "label": "Ceny z podatkiem"+ "help": "Włączone: klienci płacą wpisaną cenę z podatkiem w niej zawartym. Wyłączone: podatek jest doliczany przy kasie.",+ "label": "Ceny zawierają podatek"},"tax_provider": {"help": "Co nalicza podatek dla zamówień na tym rynku.",@@ -2239,11 +2239,6 @@"country_code": {"help": "Zostaw puste, aby opodatkować każdy kraj."},- "included_in_price": {- "help": "Ceny już zawierają ten podatek, więc jest on wyliczany z ceny, a nie doliczany.",- "label": "Wliczony w cenę",- "short": "Wliczony"- },"jurisdiction": {"label": "Obowiązuje dla"},diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.jsonindex 3beff84cb5..5eba847943 100644--- a/packages/dashboard/src/locales/zh-CN.json+++ b/packages/dashboard/src/locales/zh-CN.json@@ -1424,8 +1424,8 @@"label": "支持的语言区域"},"tax_inclusive": {- "help": "显示含税价格。在欧盟市场较为常见。",- "label": "含税定价"+ "help": "开启:顾客支付你输入的价格,税费已包含在内。关闭:在结账时加收税费。",+ "label": "价格含税"},"tax_provider": {"help": "用于计算该市场订单税费的引擎。",@@ -2216,11 +2216,6 @@"country_code": {"help": "留空表示对所有国家征税。"},- "included_in_price": {- "help": "价格已包含该税费,因此从价格中拆分而非另行加收。",- "label": "价格含税",- "short": "含税"- },"jurisdiction": {"label": "适用范围"},diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/taxes/rates.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/taxes/rates.tsxindex d64b92675e..7f447aa8d1 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/taxes/rates.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/taxes/rates.tsx@@ -10,7 +10,6 @@ import {usePermissions,} from '@spree/dashboard-core'import {- ActiveBadge,Button,Field,FieldDescription,@@ -141,7 +140,6 @@ function TaxRatesPage() {<TableHead>{t('admin.fields.tax_rate.amount.label')}</TableHead><TableHead>{t('admin.fields.tax_rate.jurisdiction.label')}</TableHead><TableHead>{t('admin.settings_nav.items.tax_categories')}</TableHead>- <TableHead>{t('admin.fields.tax_rate.included_in_price.label')}</TableHead><TableHead className="w-12" /></TableRow></TableHeader>@@ -169,13 +167,6 @@ function TaxRatesPage() {<TableCell><TaxCategoryLabel id={taxRate.tax_category_id} /></TableCell>- <TableCell>- <ActiveBadge- active={taxRate.included_in_price}- activeLabel={t('admin.fields.tax_rate.included_in_price.short')}- dashWhenInactive- />- </TableCell><TableCell><RowActionsactions={[@@ -292,7 +283,6 @@ function EditTaxRateSheet({tax_category_id: taxRate.tax_category_id ?? '',country_code: taxRate.country_code ?? '',state_code: taxRate.state_code ?? '',- included_in_price: taxRate.included_in_price,show_rate_in_label: taxRate.show_rate_in_label,})}@@ -468,30 +458,6 @@ function TaxRateFormFields({ form }: { form: UseFormReturn<TaxRateFormValues> })</Field>)}- <Field>- <div className="flex items-start justify-between gap-4">- <div className="flex flex-col">- <FieldLabel htmlFor="included_in_price" className="cursor-pointer">- {t('admin.fields.tax_rate.included_in_price.label')}- </FieldLabel>- <span className="text-xs text-muted-foreground">- {t('admin.fields.tax_rate.included_in_price.help')}- </span>- </div>- <Controller- name="included_in_price"- control={form.control}- render={({ field }) => (- <Switch- id="included_in_price"- checked={!!field.value}- onCheckedChange={field.onChange}- />- )}- />- </div>- </Field>-<Field><div className="flex items-start justify-between gap-4"><div className="flex flex-col">diff --git a/packages/dashboard/src/schemas/tax-rate.ts b/packages/dashboard/src/schemas/tax-rate.tsindex f63bd0b749..5cc7c7d450 100644--- a/packages/dashboard/src/schemas/tax-rate.ts+++ b/packages/dashboard/src/schemas/tax-rate.ts@@ -21,7 +21,6 @@ export const taxRateFormSchema = z.object({// Empty means the rate applies everywhere, so neither field is required.country_code: countryCodeSchema.or(z.literal('')).optional(),state_code: z.string().optional(),- included_in_price: z.boolean(),show_rate_in_label: z.boolean(),})@@ -33,7 +32,6 @@ export const TAX_RATE_DEFAULTS: TaxRateFormValues = {tax_category_id: '',country_code: '',state_code: '',- included_in_price: false,show_rate_in_label: false,}@@ -49,7 +47,6 @@ export function taxRateValuesToParams(values: TaxRateFormValues): TaxRateCreatePtax_category_id: values.tax_category_id,country_code: values.country_code || null,state_code: blankToNull(values.state_code),- included_in_price: values.included_in_price,show_rate_in_label: values.show_rate_in_label,}}diff --git a/spree/api/app/controllers/spree/api/v3/admin/markets_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/markets_controller.rbindex c013a79941..41bbda3ac1 100644--- a/spree/api/app/controllers/spree/api/v3/admin/markets_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/markets_controller.rb@@ -26,7 +26,9 @@ module Spreerequired: true, on: :create,example: 'de',description: 'Locale used as the market default. Always part of `supported_locales`.'- body.attribute :tax_inclusive, :boolean, description: 'Display prices with tax included.'+ body.attribute :tax_inclusive, :boolean,+ description: 'Whether the prices entered for this market include tax. True charges every customer the ' \+ 'price as entered, with their tax inside it; false adds tax at checkout.'body.attribute :tax_provider, :string,nullable: true,example: 'internal',diff --git a/spree/api/app/controllers/spree/api/v3/admin/tax_rates_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/tax_rates_controller.rbindex 614aef17ff..6c8ec97783 100644--- a/spree/api/app/controllers/spree/api/v3/admin/tax_rates_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/tax_rates_controller.rb@@ -13,7 +13,6 @@ module Spreeexample: '0.19',description: 'The rate as a fraction. Send this or `rate_percent`.'body.attribute :rate_percent, :decimal, example: '19', description: 'The rate as a percentage.'- body.attribute :included_in_price, :booleanbody.attribute :show_rate_in_label, :booleanbody.attribute :tax_category_id, :id, required: true, on: :createbody.attribute :country_code, :country,diff --git a/spree/api/app/serializers/spree/api/v3/admin/tax_rate_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/tax_rate_serializer.rbindex aa03100882..37a218ddc1 100644--- a/spree/api/app/serializers/spree/api/v3/admin/tax_rate_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/tax_rate_serializer.rb@@ -6,7 +6,6 @@ module Spree# customer-facing. What the customer sees is the label on a tax line.class TaxRateSerializer < V3::BaseSerializertypelize name: :string,- included_in_price: :boolean,show_rate_in_label: :boolean,tax_category_id: [:string, nullable: true],store_id: [:string, nullable: true],@@ -15,7 +14,7 @@ module Spreemetadata: ['Record<string, unknown>', nullable: true],deleted_at: [:string, nullable: true]- attributes :name, :included_in_price, :show_rate_in_label, :metadata,+ attributes :name, :show_rate_in_label, :metadata,created_at: :iso8601, updated_at: :iso8601, deleted_at: :iso8601rate_attributes :rate, :rate_percentdiff --git a/spree/api/spec/controllers/spree/api/v3/admin/tax_rates_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/tax_rates_controller_spec.rbindex b9a8e62204..8e235828b1 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/tax_rates_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/tax_rates_controller_spec.rb@@ -7,7 +7,7 @@ RSpec.describe Spree::Api::V3::Admin::TaxRatesController, type: :controller dolet!(:tax_category) { create(:tax_category) }let!(:germany) { Spree::Country.by_iso('DE') }- let!(:tax_rate) { create(:tax_rate, tax_category: tax_category, country_code: germany&.iso, amount: 0.19, included_in_price: true) }+ let!(:tax_rate) { create(:tax_rate, tax_category: tax_category, country_code: germany&.iso, amount: 0.19) }before { request.headers.merge!(headers) }@@ -33,7 +33,7 @@ RSpec.describe Spree::Api::V3::Admin::TaxRatesController, type: :controller doexpect(json_response['rate']).to eq('0.19')expect(json_response['rate_percent']).to eq('19')expect(json_response).not_to have_key('amount')- expect(json_response['included_in_price']).to be(true)+ expect(json_response).not_to have_key('included_in_price')expect(json_response['tax_category_id']).to eq(tax_category.prefixed_id)expect(json_response['country_code']).to eq('DE')expect(json_response['state_code']).to be_nil@@ -44,7 +44,7 @@ RSpec.describe Spree::Api::V3::Admin::TaxRatesController, type: :controller dodescribe 'POST #create' dolet(:create_params) do- { name: 'German VAT', rate: '0.19', included_in_price: true,+ { name: 'German VAT', rate: '0.19',tax_category_id: tax_category.prefixed_id, country_code: 'DE' }enddiff --git a/spree/api/spec/integration/spree/api/v3/admin/tax_rates_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/tax_rates_spec.rbindex 4500ca0435..5b87dcbcfc 100644--- a/spree/api/spec/integration/spree/api/v3/admin/tax_rates_spec.rb+++ b/spree/api/spec/integration/spree/api/v3/admin/tax_rates_spec.rb@@ -7,7 +7,7 @@ RSpec.describe 'Admin Tax Rates API', type: :request, swagger_doc: 'api-referenclet!(:tax_category) { create(:tax_category) }let!(:germany) { Spree::Country.by_iso('DE') }- let!(:tax_rate) { create(:tax_rate, tax_category: tax_category, country_code: germany&.iso, amount: 0.19, included_in_price: true) }+ let!(:tax_rate) { create(:tax_rate, tax_category: tax_category, country_code: germany&.iso, amount: 0.19) }let(:Authorization) { "Bearer #{admin_jwt_token}" }path '/api/v3/admin/tax_rates' do@@ -18,9 +18,9 @@ RSpec.describe 'Admin Tax Rates API', type: :request, swagger_doc: 'api-referencdescription <<~DESCReturns the store's tax rates. Rates are the entire configuration ofthe built-in tax provider: each pairs a tax category with a jurisdiction- (a country, optionally narrowed to one state) and a percentage, and- decides whether the tax is already included in the product price- (VAT-style) or added on top (US-style).+ (a country, optionally narrowed to one state) and a percentage. Whether+ the tax is included in the product price (VAT-style) or added on top+ (US-style) is the market's `tax_inclusive` setting.Markets using an external tax provider ignore these rows — thatprovider carries its own jurisdiction data.@@ -70,9 +70,6 @@ RSpec.describe 'Admin Tax Rates API', type: :request, swagger_doc: 'api-referencName the jurisdiction with `country_code` (and `state_code` for astate-level rate). Omitting the country makes the rate apply everywhere.-- Set `included_in_price` for VAT-style pricing, where the rate is backed- out of the displayed price rather than added to it.DESCadmin_scope :write, :settings@@ -86,7 +83,7 @@ RSpec.describe 'Admin Tax Rates API', type: :request, swagger_doc: 'api-referencresponse '201', 'tax rate created' dolet(:'x-spree-api-key') { secret_api_key.plaintext_token }let(:body) do- { name: 'VAT', rate_percent: '19', included_in_price: true,+ { name: 'VAT', rate_percent: '19',tax_category_id: tax_category.prefixed_id, country_code: 'DE' }enddiff --git a/spree/api/spec/requests/spree/api/v3/admin/tax_configuration_spec.rb b/spree/api/spec/requests/spree/api/v3/admin/tax_configuration_spec.rbindex 9e74fad37f..c3f34ae10d 100644--- a/spree/api/spec/requests/spree/api/v3/admin/tax_configuration_spec.rb+++ b/spree/api/spec/requests/spree/api/v3/admin/tax_configuration_spec.rb@@ -17,15 +17,15 @@ RSpec.describe 'Admin tax configuration', type: :request doendend- # Prices are quoted including German VAT, so the market is Germany.- before { store.default_market.update!(countries: [country]) }+ # Prices are quoted including German VAT.+ before { store.default_market.update!(countries: [country], tax_inclusive: true) }# The publishable key the storefront reads with.let(:store_headers) { { 'x-spree-api-key' => create(:api_key, :publishable, store: store).token } }it 'configures a rate and produces the tax it describes' dopost '/api/v3/admin/tax_rates',- params: { name: 'German VAT', rate_percent: '19', included_in_price: true,+ params: { name: 'German VAT', rate_percent: '19',tax_category_id: tax_category.prefixed_id, country_code: 'DE' },headers: headers, as: :json@@ -42,7 +42,7 @@ RSpec.describe 'Admin tax configuration', type: :request doit 'still records a treatment when the rate is zero' dopost '/api/v3/admin/tax_rates',- params: { name: 'German VAT', rate_percent: '19', included_in_price: true,+ params: { name: 'German VAT', rate_percent: '19',tax_category_id: tax_category.prefixed_id, country_code: 'DE' },headers: headers, as: :jsonrate_id = JSON.parse(response.body)['id']@@ -61,7 +61,7 @@ RSpec.describe 'Admin tax configuration', type: :request doit 'shows the storefront the tax on a line, without the admin treatment fields' dopost '/api/v3/admin/tax_rates',- params: { name: 'German VAT', rate_percent: '19', included_in_price: true,+ params: { name: 'German VAT', rate_percent: '19',tax_category_id: tax_category.prefixed_id, country_code: 'DE' },headers: headers, as: :jsondiff --git a/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rb b/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rbindex 1f4742c4e7..e29a9f6f02 100644--- a/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rb+++ b/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rb@@ -141,7 +141,7 @@ RSpec.describe 'Store tax identifiers', type: :request dolet(:line_item) { cart.line_items.first }let!(:tax_rate) docreate(:tax_rate, store: store, country_code: cart.tax_country&.iso,- tax_category: line_item.tax_category, amount: 0.1, included_in_price: false)+ tax_category: line_item.tax_category, amount: 0.1)endit 'happens when a registration is entered' dodiff --git a/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb b/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rbindex df135e4e02..6f6bdcc621 100644--- a/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb+++ b/spree/api/spec/serializers/spree/api/v3/delivery_rate_serializer_spec.rb@@ -66,7 +66,7 @@ RSpec.describe Spree::Api::V3::DeliveryRateSerializer doendcontext 'with additional tax' do- let(:tax_rate) { create(:tax_rate, amount: 0.1, included_in_price: false) }+ let(:tax_rate) { create(:tax_rate, amount: 0.1) }before { shipping_rate.update!(tax_rate: tax_rate) }@@ -78,9 +78,12 @@ RSpec.describe Spree::Api::V3::DeliveryRateSerializer doendcontext 'with included tax' do- let(:tax_rate) { create(:tax_rate, amount: 0.1, included_in_price: true, country_code: @default_country&.iso) }+ let(:tax_rate) { create(:tax_rate, amount: 0.1, country_code: @default_country&.iso) }- before { shipping_rate.update!(tax_rate: tax_rate) }+ before do+ shipping_rate.update!(tax_rate: tax_rate)+ allow(shipping_rate).to receive(:tax_inclusive?).and_return(true)+ endit 'returns the tax in included_tax_total' doexpect(subject['tax_total'].to_d).to be > 0diff --git a/spree/core/app/models/concerns/spree/purchase/taxation.rb b/spree/core/app/models/concerns/spree/purchase/taxation.rbindex d887992fee..0e1a0031e0 100644--- a/spree/core/app/models/concerns/spree/purchase/taxation.rb+++ b/spree/core/app/models/concerns/spree/purchase/taxation.rb@@ -28,6 +28,15 @@ module Spreemarket&.tax_provider_instance || Spree.default_tax_provider.newend+ # Whether this sale's prices include tax, which its market decides. With+ # no market yet (an empty cart before currency resolution) the store's+ # default market answers.+ #+ # @return [Boolean]+ def tax_inclusive?+ (market || store&.default_market)&.tax_inclusive? || false+ end+# The typed inputs every +estimate+ call carries. Assembled here rather# than at each call site so a single-item re-estimate reaches the provider# with the same buyer registration and exemption evidence as a full@@ -39,7 +48,8 @@ module Spree{tax_date: Time.current,tax_identifier: resolved_tax_identifier,- exemptions: usable_exemptions+ exemptions: usable_exemptions,+ tax_inclusive: tax_inclusive?}enddiff --git a/spree/core/app/models/concerns/spree/vat_price_calculation.rb b/spree/core/app/models/concerns/spree/vat_price_calculation.rbdeleted file mode 100644index ece2224b3f..0000000000--- a/spree/core/app/models/concerns/spree/vat_price_calculation.rb+++ /dev/null@@ -1,99 +0,0 @@-module Spree- # Restates a VAT-inclusive price for a customer in another country: the- # home-country VAT comes out, the destination's goes on.- #- # The including class answers +currency+, which the restated amount is- # rounded to.- module VatPriceCalculation- # Cheapest test first: a domestic sale needs no restatement whatever the- # provider is, so the provider lookup (a constantize and an instantiation) is- # skipped for every home-country price — and a market pointing at a provider- # class that is no longer loadable keeps failing only where tax is computed,- # not on every price read.- def gross_amount(amount, price_options)- return amount if amount.nil? || !outside_default_vat_zone?(price_options)- return amount unless restatement_available?(price_options)-- Spree::Money::Rounding.to_currency(add_foreign_vat_for(amount, price_options), currency)- end-- private-- # Restatement reads nothing but TaxRate rows, for both halves of the sum, so- # it only means anything where those rows are the whole truth — the Internal- # provider. Elsewhere an absent row is ambiguous: it reads as "no tax is due- # here" and deducts the home VAT, when it may only mean "this market's tax is- # computed by an engine that keeps no rows here". A market on such an engine- # would see every foreign destination treated as a zero-rated export. It- # states its destination prices through a geo-scoped price list instead.- def restatement_available?(price_options)- market = price_options[:market] || Spree::Current.market- provider = market&.tax_provider_instance || Spree.default_tax_provider.new-- provider.is_a?(Spree::TaxProvider::Internal)- end-- def add_foreign_vat_for(amount, price_options)- amount = net_amount(amount, price_options[:tax_category])- amount_with_foreign_vat(amount, price_options)- end-- def net_amount(amount, tax_category)- amount / (1 + default_vat(tax_category))- end-- def default_vat(tax_category)- included_tax_amount(country: default_tax_country, tax_category: tax_category)- end-- def foreign_vat(price_options)- included_tax_amount(price_options)- end-- def amount_with_foreign_vat(amount, price_options)- amount * (1 + foreign_vat(price_options))- end-- # Whether the price has to be restated at all.- def outside_default_vat_zone?(price_options)- country = country_from(price_options)-- country.present? && default_tax_country.present? && country != default_tax_country- end-- def included_tax_amount(price_options)- lookup = { tax_category: price_options[:tax_category] }- if price_options[:address]- lookup[:address] = price_options[:address]- else- lookup[:country] = country_from(price_options)- end-- Spree::TaxRate.included_tax_amount_for(lookup).to_d- end-- # +current_price_options+ is documented as an override point, so an app may- # still be handing us the pre-6.0 zone. Say so instead of quietly reporting- # no country, which would leave a foreign customer looking at home VAT.- def country_from(price_options)- if price_options[:tax_zone].present? && price_options[:country].blank? && price_options[:address].blank?- Spree::Deprecation.warn(- 'Passing tax_zone: in price options no longer determines tax and is ignored. ' \- 'Pass country: (a Spree::Country) or address: instead.'- )- end-- price_options[:country] || price_options[:address]&.country- end-- # The country whose VAT the catalogue prices already include. Deliberately- # the store's own country and NOT Spree::Current.market, which follows the- # buyer: reading the destination here would make every sale look domestic- # and the restatement would never fire.- def default_tax_country- return @default_tax_country if defined?(@default_tax_country)-- @default_tax_country = Spree::Current.store&.default_country- end- end-enddiff --git a/spree/core/app/models/spree/delivery_rate.rb b/spree/core/app/models/spree/delivery_rate.rbindex 984641d36a..9c0f422bbf 100644--- a/spree/core/app/models/spree/delivery_rate.rb+++ b/spree/core/app/models/spree/delivery_rate.rb@@ -41,7 +41,7 @@ module Spreereturn price if tax_rate.nil? || tax_amount.zero? || !tax_rate.show_rate_in_labelI18n.t(- "spree.shipping_rates.display_price.#{tax_rate.included_in_price? ? :including_tax : :excluding_tax}",+ "spree.shipping_rates.display_price.#{tax_inclusive? ? :including_tax : :excluding_tax}",price: price,tax_amount: display_tax_amount,tax_rate_name: tax_rate.name@@ -79,7 +79,7 @@ module Spreedef tax_amount@tax_amount ||= if tax_rate.nil?BigDecimal(0)- elsif tax_rate.included_in_price?+ elsif tax_inclusive?Spree::Money::Rounding.to_currency(cost / (1 + tax_rate.amount) * tax_rate.amount, currency)elseSpree::Money::Rounding.to_currency(cost * tax_rate.amount, currency)@@ -90,14 +90,22 @@ module Spree## @return [BigDecimal]def additional_tax_total- tax_rate&.included_in_price? ? BigDecimal(0) : tax_amount+ tax_rate && tax_inclusive? ? BigDecimal(0) : tax_amountend# Returns the included tax total for the shipping rate## @return [BigDecimal]def included_tax_total- tax_rate&.included_in_price? ? tax_amount : BigDecimal(0)+ tax_rate && tax_inclusive? ? tax_amount : BigDecimal(0)+ end++ # Whether the cost already includes its tax, which the sale's market+ # decides (Spree::Purchase::Taxation#tax_inclusive?).+ #+ # @return [Boolean]+ def tax_inclusive?+ fulfillment&.owner&.tax_inclusive? || falseendalias tax_total tax_amountdiff --git a/spree/core/app/models/spree/delivery_rate_provider/base.rb b/spree/core/app/models/spree/delivery_rate_provider/base.rbindex c76229853f..80791ff335 100644--- a/spree/core/app/models/spree/delivery_rate_provider/base.rb+++ b/spree/core/app/models/spree/delivery_rate_provider/base.rb@@ -6,7 +6,7 @@ module Spree# Stored as a string class name on DeliveryMethod and constantized at call# time; registered via Spree.delivery_rate_providers. The Estimator# dispatches here in place of calling the calculator directly, so- # filtering, VAT gross-up, tax resolution and sorting stay in one place+ # filtering, markup, tax resolution and sorting stay in one place# for every provider.## External providers resolve credentials through the delivery method'sdiff --git a/spree/core/app/models/spree/delivery_rate_provider/estimate.rb b/spree/core/app/models/spree/delivery_rate_provider/estimate.rbindex 6cc83570b8..81b897c78f 100644--- a/spree/core/app/models/spree/delivery_rate_provider/estimate.rb+++ b/spree/core/app/models/spree/delivery_rate_provider/estimate.rb@@ -2,10 +2,11 @@ module Spreemodule DeliveryRateProvider# A single quote returned by a delivery rate provider.#- # +cost+ is pre-tax and pre-VAT-gross-up: the Estimator applies- # +gross_amount+ and resolves the tax rate afterwards, exactly as it does- # for calculator output. Everything else is carrier metadata that flows- # onto the persisted DeliveryRate.+ # +cost+ is the quoted price: the Estimator adds markup and resolves the+ # tax rate afterwards, exactly as it does for calculator output, and the+ # market decides whether that tax is inside the cost or added on top.+ # Everything else is carrier metadata that flows onto the persisted+ # DeliveryRate.class Estimateinclude ActiveModel::Modelinclude ActiveModel::Attributesdiff --git a/spree/core/app/models/spree/line_item.rb b/spree/core/app/models/spree/line_item.rbindex 98b6cf12ba..0fbd0f625c 100644--- a/spree/core/app/models/spree/line_item.rb+++ b/spree/core/app/models/spree/line_item.rb@@ -158,12 +158,6 @@ module Spree# Assigns the current price without saving — the caller is expected to.# {#recalculate_price} persists instead.- #- # Restatement for a tax-inclusive market happens inside- # {Spree::Carts::PriceItems}: an address-less cart still has a taxing- # country (its market's own), and without it a cross-border cart is taxed- # for the destination at a price quoted for home, leaving the merchant to- # absorb the difference.# persist: false — runs mid-build and from callers that save the record# themselves.def update_price@@ -181,8 +175,8 @@ module Spreeprice_record = Spree::PricingProvider::Internal.new.price_for(context)return if price_record.blank?- # Through the same writer every resolved price goes through, so the- # tax-inclusive restatement inputs are stated once.+ # Through the same writer every resolved price goes through, so a line+ # built here is priced exactly like a resolved one.Spree::Carts::PriceItems.apply([[self, price_record]], persist: false)enddiff --git a/spree/core/app/models/spree/price.rb b/spree/core/app/models/spree/price.rbindex df8eeade68..9169c7efa6 100644--- a/spree/core/app/models/spree/price.rb+++ b/spree/core/app/models/spree/price.rb@@ -9,7 +9,6 @@ module Spreehas_prefix_id :price- include Spree::VatPriceCalculationinclude Spree::StorePreferencesinclude Spree::CanonicalDecimals@@ -135,44 +134,28 @@ module Spreealias_attribute :price, :amountalias_attribute :compare_at_price, :compare_at_amount- # Whether this figure is the merchant's answer for the buyer's geography- # already. A price list narrowed by market or country states its prices for- # that geography, so they are charged exactly as entered — restating one would- # net it out with the *home* rate and destroy the price point the merchant- # chose. Lists narrowed by anything else (a quantity, a group) were not set- # for a country, so their prices restate like any other.- #- # @return [Boolean]- def final_for_destination?- rules = price_list&.price_rules.to_a- return false unless rules.any?(&:geographic?)-- # Under 'any' the list can win on a non-geographic rule alone, so a- # geographic rule being present does not mean this buyer's geography is why- # the price applied. Under 'all' every rule matched, so it does.- price_list.match_policy == 'all' || rules.all?(&:geographic?)- end-- def price_including_vat_for(price_options)- return price if final_for_destination?-- options = price_options.merge(tax_category: variant.tax_category)- gross_amount(price, options)+ # @deprecated Prices are charged as entered for every buyer since 6.0. Use {#price}; removed in 6.1.+ def price_including_vat_for(_price_options = {})+ Spree::Deprecation.warn('Spree::Price#price_including_vat_for is deprecated and will be removed in Spree 6.1. Prices are charged as entered; use #price instead.')+ priceend- def compare_at_price_including_vat_for(price_options)- return compare_at_price if final_for_destination?-- options = price_options.merge(tax_category: variant.tax_category)- gross_amount(compare_at_price, options)+ # @deprecated Use {#compare_at_price}; removed in 6.1.+ def compare_at_price_including_vat_for(_price_options = {})+ Spree::Deprecation.warn('Spree::Price#compare_at_price_including_vat_for is deprecated and will be removed in Spree 6.1. Prices are charged as entered; use #compare_at_price instead.')+ compare_at_priceend- def display_price_including_vat_for(price_options)- Spree::Money.new(price_including_vat_for(price_options), currency: currency)+ # @deprecated Use {#display_price}; removed in 6.1.+ def display_price_including_vat_for(_price_options = {})+ Spree::Deprecation.warn('Spree::Price#display_price_including_vat_for is deprecated and will be removed in Spree 6.1. Prices are charged as entered; use #display_price instead.')+ display_priceend- def display_compare_at_price_including_vat_for(price_options)- Spree::Money.new(compare_at_price_including_vat_for(price_options), currency: currency)+ # @deprecated Use {#display_compare_at_price}; removed in 6.1.+ def display_compare_at_price_including_vat_for(_price_options = {})+ Spree::Deprecation.warn('Spree::Price#display_compare_at_price_including_vat_for is deprecated and will be removed in Spree 6.1. Prices are charged as entered; use #display_compare_at_price instead.')+ display_compare_at_priceend# returns the name of the price in a format of variant name and currencydiff --git a/spree/core/app/models/spree/price_rule.rb b/spree/core/app/models/spree/price_rule.rbindex 45e046bfd7..9a103ffee1 100644--- a/spree/core/app/models/spree/price_rule.rb+++ b/spree/core/app/models/spree/price_rule.rb@@ -16,18 +16,6 @@ module Spreeraise NotImplementedError, "#{self.class.name} must implement #applicable?"end- # Whether this rule narrows its price list by geography. A list carrying one- # states the price for that geography outright, so its prices are charged as- # entered and never restated for the buyer's VAT rate- # (Spree::VatPriceCalculation). A rule that narrows by anything else — a- # quantity, a group, a channel — leaves its prices open to restatement, since- # they were not set for a country.- #- # @return [Boolean]- def geographic?- false- end-# Whether this rule narrows by something about the purchase rather than# about the buyer. A catalog-owned price list has already been matched on# audience by the time the resolver holds it — the catalog assignment is@@ -45,10 +33,9 @@ module Spreefalseend- # Instance-side reader, so rules are classified the same way- # `geographic?` classifies them (`rules.any?(&:geographic?)`). A kind- # whose answer depends on how it is configured overrides this, exactly- # as MarketRule does for `geographic?`.+ # Instance-side reader, so rules can be classified per row+ # (`price_rules.select(&:contextual?)`). A kind whose answer depends on how it is+ # configured overrides this.## @return [Boolean]def contextual?diff --git a/spree/core/app/models/spree/price_rules/market_rule.rb b/spree/core/app/models/spree/price_rules/market_rule.rbindex 67897ee51e..0cfbe7c486 100644--- a/spree/core/app/models/spree/price_rules/market_rule.rb+++ b/spree/core/app/models/spree/price_rules/market_rule.rb@@ -23,12 +23,6 @@ module Spreepreferred_market_ids.map(&:to_s).include?(context.market.id.to_s)end- # An empty market list matches every buyer (see #applicable?), so it names- # no geography — and that is the state a freshly created rule row is in.- def geographic?- preferred_market_ids.present?- end-def self.description'Apply pricing based on the market'enddiff --git a/spree/core/app/models/spree/pricing_provider/base.rb b/spree/core/app/models/spree/pricing_provider/base.rbindex 48ada58ec1..3fb6d6d8d5 100644--- a/spree/core/app/models/spree/pricing_provider/base.rb+++ b/spree/core/app/models/spree/pricing_provider/base.rb@@ -6,7 +6,7 @@ module Spree# A provider returns a {Spree::Price}: {Internal} returns the persisted# catalog row, an external provider an **unsaved, readonly** instance. The# Active Record shape is deliberately the contract, so everything- # downstream — tax-inclusive restatement, +discounted?+, the serializers —+ # downstream — the line item, +discounted?+, the serializers —# keeps working without knowing where the number came from. +readonly!+ is# what stops an external answer being written back into the catalog.#diff --git a/spree/core/app/models/spree/stock/estimator.rb b/spree/core/app/models/spree/stock/estimator.rbindex 5fc3013d56..89d26101e4 100644--- a/spree/core/app/models/spree/stock/estimator.rb+++ b/spree/core/app/models/spree/stock/estimator.rb@@ -1,8 +1,6 @@module Spreemodule Stockclass Estimator- include Spree::VatPriceCalculation-attr_reader :order, :currencydef initialize(order)@@ -69,7 +67,7 @@ module Spree# through the calculator, carrier providers call their API and may# return several estimates (one per carrier service). An empty result# suppresses the method, matching the calculator contract. Service- # filtering, markup, naming, VAT gross-up, tax resolution and sorting+ # filtering, markup, naming, tax resolution and sorting# stay here so every provider gets them identically.def calculate_delivery_rates(package, audience)delivery_methods(package, audience).flat_map do |delivery_method|@@ -103,14 +101,12 @@ module Spreeend# An unpriced quote has no amount to mark up or tax — a percentage of an- # unknown price is still unknown, and rounding zero through the VAT- # gross-up would only invent a number. Its cost stays zero and every- # display surface reads +unpriced+ instead.+ # unknown price is still unknown. Its cost stays zero and every display+ # surface reads +unpriced+ instead.def rate_cost(estimate, delivery_method, service_row, provider)return 0 if estimate.unpriced- cost = apply_markup(estimate.cost, delivery_method, service_row, provider)- gross_amount(cost, taxation_options_for(delivery_method))+ apply_markup(estimate.cost, delivery_method, service_row, provider)end# Handling fee on top of provider quotes: the service row's values when@@ -132,18 +128,6 @@ module Spree[estimate.carrier, estimate.service_level].compact.join(' ').presenceend- # Override this if you need the prices for delivery methods to be handled just like the- # prices for products in terms of included tax manipulation.- #- def taxation_options_for(delivery_method)- {- tax_category: delivery_method.tax_category,- address: @order.tax_address,- country: @order.tax_country,- market: @order.market- }- end-def first_tax_rate_for(tax_category)return unless @order.tax_address && tax_categorydiff --git a/spree/core/app/models/spree/tax_provider/base.rb b/spree/core/app/models/spree/tax_provider/base.rbindex 5394de7c9e..c4f7bec942 100644--- a/spree/core/app/models/spree/tax_provider/base.rb+++ b/spree/core/app/models/spree/tax_provider/base.rb@@ -96,6 +96,9 @@ module Spree# @param tax_identifier [Spree::TaxIdentifier, nil] resolved buyer# registration, nil for a consumer sale# @param exemptions [Array] exemption evidence to apply+ # @param tax_inclusive [Boolean, nil] whether the owner's prices already+ # include tax, which its market decides (Spree::Market#tax_inclusive);+ # nil = ask the owner (+owner.tax_inclusive?+)# @param context [Hash] untyped provider extras from set_tax_line_context# @return [void] the written rows are the output# @raise [Spree::Tax::ProviderUnavailable] when the engine could not@@ -104,7 +107,7 @@ module Spree# turns it into a refusal the customer can retry, where anything else# reaches them as a broken checkout. A provider a merchant switched off# is not this — it has no opinion and writes no rows.- def estimate(owner, items = nil, tax_date: nil, tax_identifier: nil, exemptions: [], context: {})+ def estimate(owner, items = nil, tax_date: nil, tax_identifier: nil, exemptions: [], tax_inclusive: nil, context: {})raise NotImplementedError, "Please implement 'estimate' in your tax provider: #{self.class.name}"end@@ -187,9 +190,10 @@ module Spree# @param tax_date [Time, nil] date whose rates apply; nil = now# @param tax_identifier [Spree::TaxIdentifier, nil] the order's frozen registration# @param exemptions [Array] exemption evidence to apply+ # @param tax_inclusive [Boolean, nil] as for +estimate+# @return [void]# @raise [Spree::Tax::ProviderError] when the tax could not be worked out- def estimate_replacement(order, items, tax_date: nil, tax_identifier: nil, exemptions: [])+ def estimate_replacement(order, items, tax_date: nil, tax_identifier: nil, exemptions: [], tax_inclusive: nil)raise NotImplementedError, "Please implement 'estimate_replacement' in your tax provider: #{self.class.name}"enddiff --git a/spree/core/app/models/spree/tax_provider/internal.rb b/spree/core/app/models/spree/tax_provider/internal.rbindex 16a82cc3ea..0bd99e4716 100644--- a/spree/core/app/models/spree/tax_provider/internal.rb+++ b/spree/core/app/models/spree/tax_provider/internal.rb@@ -1,7 +1,8 @@module Spreemodule TaxProvider# Computes tax directly from TaxRate configuration: rate × discounted- # base, with VAT included-in-price math backed out of the gross basis.+ # base, backed out of the price instead when the market's prices include+ # tax.# Rates are matched on the owner's tax address, each naming its own country# and optionally a state. Fees without a tax category are taxed with the# default tax category's rates — except customs duties, which +taxable_items+@@ -26,7 +27,8 @@ module Spree# period, so there is only ever one version of the configuration to read.# +tax_identifier+ likewise — reverse charge is on the unsupported list,# so a buyer registration changes nothing here.- def estimate(owner, items = nil, tax_date: nil, tax_identifier: nil, exemptions: [], context: {})+ def estimate(owner, items = nil, tax_date: nil, tax_identifier: nil, exemptions: [], tax_inclusive: nil, context: {})+ tax_inclusive = owner.tax_inclusive? if tax_inclusive.nil?full_estimate = items.nil?items ||= owner.taxable_items# A duty this engine taxed before it was excluded — or through an@@ -44,7 +46,7 @@ module SpreeSpree::TaxLine.where(Spree::TaxLine.adjustable_key_for(klass) => group.map(&:id)).delete_allend- items.each { |item| tax_item(owner, item, rates, exemptions) }+ items.each { |item| tax_item(owner, item, rates, exemptions, tax_inclusive) }end# Gives back each credited unit's share of the TaxLines the sale actually@@ -63,16 +65,17 @@ module Spree# An exemption is read as it applied to the line being replaced: a# certificate's per-line carve-out names that line, and the exchange line# replacing it would otherwise match no carve-out and come out exempt.- def estimate_replacement(order, items, tax_date: nil, tax_identifier: nil, exemptions: [])+ def estimate_replacement(order, items, tax_date: nil, tax_identifier: nil, exemptions: [], tax_inclusive: nil)return if items.empty?+ tax_inclusive = order.tax_inclusive? if tax_inclusive.nil?Spree::TaxLine.charges.where(exchange_line_item_id: items.map(&:id)).delete_allrates = rates_for(order)items.each do |item|next unless item.credited_quantity.to_i.positive?- tax_item(order, item, rates, exemptions, exemption_subject: item.line_item || item)+ tax_item(order, item, rates, exemptions, tax_inclusive, exemption_subject: item.line_item || item)endend@@ -80,11 +83,8 @@ module Spree# else, matched on where the invoiced business sits and taxed under the# store's default category — this engine has no separate notion of a# services category, and a marketplace commission is standard-rated- # nearly everywhere.- #- # Additional (not included-in-price) rates only: a commission is quoted- # net and its VAT is added on top, so a rate configured as- # tax-inclusive describes consumer pricing rather than this supply.+ # nearly everywhere. A commission is quoted net and its tax added on top,+ # whatever the store's markets do with their prices.## Nil when the jurisdiction is unknown or configured with no matching# rate at all, so the caller falls back to its own default instead of@@ -97,8 +97,7 @@ module Spreerates = Spree::TaxRate.for_store(store).for_jurisdiction(address.country_code, address.state_code).- for_tax_category(category).- where(included_in_price: false)+ for_tax_category(category)return nil if rates.empty?rates.sum(:amount)@@ -120,7 +119,7 @@ module SpreeSpree::TaxRate.for_store(owner.store).for_jurisdiction(owner.tax_country&.iso, owner.tax_address&.state_code).to_aend- def tax_item(owner, item, rates, exemptions, exemption_subject: item)+ def tax_item(owner, item, rates, exemptions, tax_inclusive, exemption_subject: item)relevant_rates = rates.select { |rate| rate.tax_category_id == tax_category_id_for(item, owner) }# A matched rate always produces a row, zero-amount ones included:@@ -135,15 +134,15 @@ module Spree# An exempt item has no tax to back out of its price, so its whole# basis is pre-tax.exempt_rates = taxed.select { |_rate, _jurisdiction, exemption| exemption }.map(&:first)- store_pre_tax_amount(item, relevant_rates - exempt_rates)+ store_pre_tax_amount(item, relevant_rates - exempt_rates, tax_inclusive)taxed.each do |rate, jurisdiction, exemption|if exemption- write_tax_line(owner, item, rate, 0, 'customer_exempt', jurisdiction,+ write_tax_line(owner, item, rate, 0, 'customer_exempt', jurisdiction, tax_inclusive,data: exemption_data(exemption, exemption_subject))else- write_tax_line(owner, item, rate, compute_tax(rate, item, relevant_rates, owner.currency),- reason_for(rate), jurisdiction)+ write_tax_line(owner, item, rate, compute_tax(rate, item, relevant_rates, owner.currency, tax_inclusive),+ reason_for(rate), jurisdiction, tax_inclusive)endendend@@ -177,13 +176,11 @@ module Spree# Rounded per line, half up, to the order's currency — the internal# provider's choice; other providers round as their jurisdictions require.- def compute_tax(rate, item, relevant_rates, currency)+ def compute_tax(rate, item, relevant_rates, currency, tax_inclusive)basis = taxable_basis(item)- tax = if rate.included_in_price- included_sum = relevant_rates.select(&:included_in_price).sum(&:amount)- included_sum = rate.amount if included_sum.zero?- basis / (1 + included_sum) * rate.amount+ tax = if tax_inclusive+ basis / (1 + relevant_rates.sum(&:amount)) * rate.amountelsebasis * rate.amountend@@ -192,12 +189,11 @@ module Spree# Pre-tax amounts are stored so refund and reporting code can weigh# discounted, tax-exclusive values later (see #4318).- def store_pre_tax_amount(item, rates)+ def store_pre_tax_amount(item, rates, tax_inclusive)return unless item.respond_to?(:pre_tax_amount)pre_tax_amount = taxable_basis(item)- included_rates = rates.select(&:included_in_price)- pre_tax_amount /= (1 + included_rates.sum(&:amount)) if included_rates.any?+ pre_tax_amount /= (1 + rates.sum(&:amount)) if tax_inclusive && rates.any?item.update_column(:pre_tax_amount, pre_tax_amount)end@@ -245,7 +241,7 @@ module Spree}end- def write_tax_line(owner, item, rate, amount, reason, jurisdiction, data: {})+ def write_tax_line(owner, item, rate, amount, reason, jurisdiction, tax_inclusive, data: {})owner_key = owner.is_a?(Spree::Order) ? :order : :cartSpree::TaxLine.create!({@@ -254,8 +250,8 @@ module Spreetax_rate: rate,amount: amount,rate: rate.amount,- label: rate.adjustment_label,- included: rate.included_in_price,+ label: rate.adjustment_label(included: tax_inclusive),+ included: tax_inclusive,provider_id: 'internal',taxability_reason: reason,data: datadiff --git a/spree/core/app/models/spree/tax_rate.rb b/spree/core/app/models/spree/tax_rate.rbindex ae12dba400..98031ab03d 100644--- a/spree/core/app/models/spree/tax_rate.rb+++ b/spree/core/app/models/spree/tax_rate.rb@@ -9,6 +9,10 @@ module Spree# zone_id any more, but the column stays in the database through 6.0: it is# what `spree:migrate_tax_zones` converts from, and that task runs after# db:migrate. The physical drop lands in 6.1.+ #+ # The same goes for included_in_price: whether tax sits inside a price is+ # the market's choice (Spree::Market#tax_inclusive), and the column is read+ # only by `spree:markets:backfill_tax_inclusive`, which clears it.acts_as_paranoid@@ -52,15 +56,10 @@ module Spree}# The same question asked with an address in hand.scope :for_address, ->(address) { for_jurisdiction(address&.country_code, address&.state_code) }- # Country-wide: unlike for_jurisdiction(country_code, nil) this leaves the- # state unconstrained, so it sums a country's state-level rates too. Used- # where the state is irrelevant — backing VAT out of a gross price.- scope :for_country, ->(country_code) { where(country_code: [country_code.presence, nil].uniq) }scope :for_tax_category,->(category) { where(tax_category_id: category.try(:id)) }- scope :included_in_price, -> { where(included_in_price: true) }- self.whitelisted_ransackable_attributes = %w[amount rate country_code state_code tax_category_id included_in_price name]+ self.whitelisted_ransackable_attributes = %w[amount rate country_code state_code tax_category_id name]ransack_alias :rate, :amountsearch_by :name@@ -92,38 +91,13 @@ module Spreeself.rate_percent = valueend- # The included-in-price rate to back out of a gross price.- #- # @param options [Hash] +:country+ (or +:address+) and +:tax_category+- # @return [BigDecimal] 0 when the jurisdiction or category is unknown- def self.included_tax_amount_for(options)- # +:country+ is a documented override point and the VAT path still hands- # it a Spree::Country, so take the code off whichever arrives.- country = options[:country]- country_code = country.try(:iso) || country.presence || options[:address]&.country_code- return 0 unless country_code && options[:tax_category]-- scope = options[:address] ? for_address(options[:address]) : for_country(country_code)- # Per-store tax configuration is the norm since 6.0, so without this the- # sum would add up every store's rate for the same country.- store = options[:store] || Spree::Current.store- scope = scope.for_store(store) if store- scope.included_in_price.for_tax_category(options[:tax_category]).sum(:amount)- end-- def included?- included_in_price- end-- def additional?- !included_in_price- end-# The customer-facing label snapshotted onto TaxLine rows.#+ # @param included [Boolean] whether the tax sits inside the price, which+ # the sale's market decides (Spree::Market#tax_inclusive)# @return [String]- def adjustment_label- I18n.t "spree.adjustment_labels.tax_rates.#{included_in_price? ? :including_tax : :excluding_tax}",+ def adjustment_label(included: false)+ I18n.t "spree.adjustment_labels.tax_rates.#{included ? :including_tax : :excluding_tax}",name: name.presence || tax_category.name,amount: amount_for_labelenddiff --git a/spree/core/app/services/spree/carts/price_items.rb b/spree/core/app/services/spree/carts/price_items.rbindex d072e70a69..f0257cddf6 100644--- a/spree/core/app/services/spree/carts/price_items.rb+++ b/spree/core/app/services/spree/carts/price_items.rb@@ -71,20 +71,14 @@ module Spreeresolutions = Array(resolutions)return if resolutions.empty?- # One derivation for the batch: every line in a resolution set belongs- # to the same cart, and tax_address / tax_country walk associations and- # a store preference that would otherwise be re-read per line.- owner = resolutions.first.first.owner- vat_inputs = { address: owner&.tax_address, country: owner&.tax_country, market: owner&.market }-resolutions.each do |line_item, price|# Probe-based flows resolve against stand-ins, so the guard has to# hold at the write too.next if line_item.manual_price?- amount = price.price_including_vat_for(**vat_inputs)+ amount = price.price# Marked before the blank guard: the provider has already answered,- # so a restatement that comes back blank must still not send the+ # so a price that comes back blank must still not send the# after_save callback back to the provider from inside the caller's# transaction. Only the assign-for-a-coming-save case needs it — a# persisted write goes through update_columns and fires no callbacks.diff --git a/spree/core/app/workflows/spree/catalogs/set_price_list.rb b/spree/core/app/workflows/spree/catalogs/set_price_list.rbindex 7b615ce125..1b34722ddf 100644--- a/spree/core/app/workflows/spree/catalogs/set_price_list.rb+++ b/spree/core/app/workflows/spree/catalogs/set_price_list.rb@@ -90,8 +90,8 @@ module Spree# settled by its assignments. Rules are reconciled by replacement, so# the audience rules the caller never mentioned are merged back in;# without this, editing a catalog's name through the inline payload- # would destroy a market rule and silently change how its prices are- # restated for VAT.+ # would destroy a market rule and silently change which buyers its+ # prices apply to.def merged_rules(rows)existing = catalog.price_list&.price_rules&.to_a || []untouched = existing.reject(&:contextual?)diff --git a/spree/core/db/migrate/20261016000001_remove_default_from_spree_tax_rates_included_in_price.rb b/spree/core/db/migrate/20261016000001_remove_default_from_spree_tax_rates_included_in_price.rbnew file mode 100644index 0000000000..9b02196850--- /dev/null+++ b/spree/core/db/migrate/20261016000001_remove_default_from_spree_tax_rates_included_in_price.rb@@ -0,0 +1,9 @@+# Whether tax sits inside a price is the market's setting now, and the column is+# read once by `spree:markets:backfill_tax_inclusive`. New rates leave it empty,+# so that step, which every later upgrade runs again, never mistakes one for a+# rate whose tax was added on top. The column is dropped in 6.1.+class RemoveDefaultFromSpreeTaxRatesIncludedInPrice < ActiveRecord::Migration[8.1]+ def change+ change_column_default :spree_tax_rates, :included_in_price, from: false, to: nil+ end+enddiff --git a/spree/core/db/sample_data/orders.rb b/spree/core/db/sample_data/orders.rbindex 91ce0e02e2..91e36364fc 100644--- a/spree/core/db/sample_data/orders.rb+++ b/spree/core/db/sample_data/orders.rb@@ -98,7 +98,7 @@ if tax_rate).first_or_create! do |tax_line|tax_line.amount = 0tax_line.rate = tax_rate.amount- tax_line.included = tax_rate.included_in_price+ tax_line.included = order.tax_inclusive?tax_line.provider_id = 'internal'endenddiff --git a/spree/core/lib/spree/core/controller_helpers/store.rb b/spree/core/lib/spree/core/controller_helpers/store.rbindex fbd79ec1ea..7b21811d47 100644--- a/spree/core/lib/spree/core/controller_helpers/store.rb+++ b/spree/core/lib/spree/core/controller_helpers/store.rb@@ -37,19 +37,9 @@ module Spree# Return a Hash of things that influence the prices displayed in your shop.#- # By default, the only thing that influences prices is the country whose tax applies (to- # facilitate differing prices depending on VAT rate for digital products in Europe, see- # https://github.com/spree/spree/pull/6295 and https://github.com/spree/spree/pull/6662).- #- # If your prices depend on something else, overwrite this method and add- # more key/value pairs to the Hash it returns.- #- # Be careful though to also patch the following parts of Spree accordingly:- #- # * `Spree::VatPriceCalculation#gross_amount`- # * `Spree::LineItem#update_price`- # * `Spree::Stock::Estimator#taxation_options_for`- #+ # By default that is the country whose tax applies. If your prices depend+ # on something else, overwrite this method and add more key/value pairs+ # to the Hash it returns.def current_price_options{country: current_tax_countrydiff --git a/spree/core/lib/spree/core/pricing/price_resolution.rb b/spree/core/lib/spree/core/pricing/price_resolution.rbindex 66d1cdf4cc..4f61db524e 100644--- a/spree/core/lib/spree/core/pricing/price_resolution.rb+++ b/spree/core/lib/spree/core/pricing/price_resolution.rb@@ -103,10 +103,10 @@ module Spreedef stamp(price)return if price.blank?- # The context always knows the variant, and the tax-inclusive- # restatement reads it — a provider that builds a Price without one- # would otherwise fail deep in that call with an obscure NoMethodError- # rather than anywhere near the provider that omitted it.+ # The context always knows the variant, and everything downstream+ # reads it — a provider that builds a Price without one would otherwise+ # fail far from the provider that omitted it, with an obscure+ # NoMethodError.price.variant ||= context.variantprice.readonly!price.price_source = provider.class.keydiff --git a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.ymlindex 61568532fe..0e1c2f15c7 100644--- a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml+++ b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml@@ -470,6 +470,28 @@ steps:once several stores hold tax configuration. The NOT NULL constraints landin 6.1. Idempotent.+ - id: backfill_market_tax_inclusive+ name: "Decide whether each market's prices include tax"+ task: "spree:markets:backfill_tax_inclusive"+ notes: |+ In Spree 6 the market decides whether its prices include tax; tax rates+ no longer carry an "included in price" flag. Each market takes the+ convention its rates had: all included sets it to include tax, all added+ on top sets it to add tax at checkout, and a market with no rates keeps+ its setting. A market whose rates mixed the two is left unchanged and+ named in the output, to be set by hand.++ Prices are no longer adjusted for buyers abroad. A store that had a+ default tax zone in 5.x and prices including tax now charges buyers+ outside that zone the price as entered, with their own tax inside it.+ Prices with tax added on top were never adjusted, and still have tax+ added at checkout.++ Run after migrate_tax_zones and backfill_tax_store_ids, which give each+ rate its country and store; it stops if a rate still has no store.+ Idempotent: each rate's old flag is read once and then cleared, so a+ re-run leaves every market as it is.+- id: backfill_order_coupon_codesname: "Backfill coupon codes on placed orders"task: "spree:backfill_order_coupon_codes"diff --git a/spree/core/lib/tasks/markets.rake b/spree/core/lib/tasks/markets.rakeindex 076f129a89..637cfed107 100644--- a/spree/core/lib/tasks/markets.rake+++ b/spree/core/lib/tasks/markets.rake@@ -42,5 +42,52 @@ namespace :spree doputs " Created market '#{market.name}' with #{countries.size} countries for store '#{store.name}' (#{store.code})"endend++ desc "Set each market's tax_inclusive from whether its tax rates were included in the price"+ task backfill_tax_inclusive: :environment do+ # A rate with no store is one spree:backfill_tax_store_ids has not bound+ # yet, and a market decided without it would be decided on part of its rates.+ if Spree::TaxRate.with_deleted.where(store_id: nil).where.not(included_in_price: nil).exists?+ abort ' Some tax rates have no store yet. Run spree:backfill_tax_store_ids first, then run this again.'+ end++ updated = 0+ mixed = []++ Spree::Store.find_each do |store|+ # Each rate's old flag is read once and then cleared, so a re-run finds+ # nothing to read and cannot undo a market the merchant changed since.+ legacy_rates = Spree::TaxRate.with_deleted.where(store_id: store.id).where.not(included_in_price: nil)+ next unless legacy_rates.exists?++ ActiveRecord::Base.transaction do+ store.markets.includes(:market_countries).find_each do |market|+ # A rate with no country taxes every market's countries.+ conventions = legacy_rates.where(deleted_at: nil, country_code: market.country_codes + [nil]).+ distinct.pluck(:included_in_price)+ next if conventions.empty?++ if conventions.size > 1+ mixed << market+ next+ end+ next if market.tax_inclusive == conventions.first++ market.update_columns(tax_inclusive: conventions.first, updated_at: Time.current)+ updated += 1+ end++ legacy_rates.update_all(included_in_price: nil)+ store.touch+ end+ end++ puts " Set tax_inclusive on #{updated} market(s) from their tax rates."++ mixed.each do |market|+ puts " ! Left '#{market.name}' (store #{market.store.code}) unchanged: some of its rates were included in " \+ "the price and some added on top. Set whether its prices include tax in the dashboard."+ end+ endendenddiff --git a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rbindex 393504536a..e5a5a9cc7e 100644--- a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb+++ b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb@@ -556,6 +556,81 @@ describe '6.0 data migration tasks' doendend+ describe 'spree:markets:backfill_tax_inclusive' do+ let(:tax_store) { create(:store) }+ let(:tax_category) { create(:tax_category, store: tax_store) }+ let!(:market) { create(:market, store: tax_store, countries: [Spree::Country.by_iso('DE')]) }++ def legacy_rate(country_code, included:)+ create(:tax_rate, store: tax_store, tax_category: tax_category, country_code: country_code, included_in_price: included)+ end++ it 'includes tax in the prices of a market whose rates were included in the price' do+ legacy_rate('DE', included: true)+ legacy_rate(nil, included: true)++ run_task('spree:markets:backfill_tax_inclusive')++ expect(market.reload).to be_tax_inclusive+ end++ it 'adds tax on top in a market whose rates were added on top' do+ market.update_column(:tax_inclusive, true)+ legacy_rate('DE', included: false)++ run_task('spree:markets:backfill_tax_inclusive')++ expect(market.reload).not_to be_tax_inclusive+ end++ it 'leaves a market whose rates mixed the two for the merchant to set' do+ market.update_column(:tax_inclusive, true)+ legacy_rate('DE', included: false)+ legacy_rate(nil, included: true)++ run_task('spree:markets:backfill_tax_inclusive')++ expect(market.reload).to be_tax_inclusive+ end++ it "reads only the market's own store's rates" do+ create(:tax_rate, store: store, country_code: 'DE', included_in_price: true)++ run_task('spree:markets:backfill_tax_inclusive')++ expect(market.reload).not_to be_tax_inclusive+ end++ it 'stops while some rates have no store yet' do+ legacy_rate('DE', included: true).update_column(:store_id, nil)++ expect { run_task('spree:markets:backfill_tax_inclusive') }.+ to raise_error(SystemExit, /spree:backfill_tax_store_ids/).and output.to_stderr+ expect(market.reload).not_to be_tax_inclusive+ end++ # Every upgrade walks every manifest, so this runs again on later upgrades.+ it 'reads each old flag once, so running again keeps what the merchant set since' do+ rate = legacy_rate('DE', included: true)+ run_task('spree:markets:backfill_tax_inclusive')+ market.update_column(:tax_inclusive, false)++ run_task('spree:markets:backfill_tax_inclusive')++ expect(rate.reload.included_in_price).to be_nil+ expect(market.reload).not_to be_tax_inclusive+ end++ it 'leaves a market alone whose rates were all created after the upgrade' do+ market.update_column(:tax_inclusive, true)+ create(:tax_rate, store: tax_store, tax_category: tax_category, country_code: 'DE')++ run_task('spree:markets:backfill_tax_inclusive')++ expect(market.reload).to be_tax_inclusive+ end+ end+describe 'spree:backfill_order_markets' doit 'assigns the store default market to orders missing one' doorder = create(:order, store: store)diff --git a/spree/core/spec/models/concerns/spree/vat_price_calculation_spec.rb b/spree/core/spec/models/concerns/spree/vat_price_calculation_spec.rbdeleted file mode 100644index 66c081b281..0000000000--- a/spree/core/spec/models/concerns/spree/vat_price_calculation_spec.rb+++ /dev/null@@ -1,217 +0,0 @@-require 'spec_helper'--# The cross-border matrix. A tax-inclusive price is expressed in some country's-# VAT, so shipping elsewhere has to restate it: the home rate out, the-# destination's on. Nothing covered this from the cart side before — the existing-# coverage in tax_rate_spec.rb drives the order path.-describe Spree::VatPriceCalculation, type: :model do- let(:store) { @default_store }- let(:germany) { Spree::Country.by_iso('DE') }- let(:france) { Spree::Country.by_iso('FR') }- let(:japan) { Spree::Country.by_iso('JP') }- let(:category) { create(:tax_category, name: "Goods #{Time.current.to_f}") }-- # Prices are quoted including German VAT, so Germany is the home zone.- let(:home_market) { store.default_market }-- before do- home_market.update!(countries: [germany])- create(:tax_rate, name: 'DE 19% incl', amount: 0.19, tax_category: category,- country_code: germany&.iso, included_in_price: true, store: store)- end-- let(:variant) { create(:variant, price: 100, product: create(:product, tax_category: category)) }- let(:price) { variant.prices.find_by(currency: 'USD', price_list_id: nil) }-- def gross_for(country, market: home_market)- price.price_including_vat_for(country: country, market: market)- end-- it 'leaves the price alone when the destination is the home country' do- expect(gross_for(germany)).to eq(100.00)- end-- it 'restates for a destination with its own rate, preserving the net' do- create(:tax_rate, name: 'FR 20% incl', amount: 0.20, tax_category: category,- country_code: france&.iso, included_in_price: true, store: store)-- # net 100 / 1.19 = 84.0336, grossed by 1.20- expect(gross_for(france)).to eq(100.84)- end-- context 'rounding conformance' do- before do- create(:tax_rate, name: 'FR 20% incl', amount: 0.20, tax_category: category,- country_code: france&.iso, included_in_price: true, store: store)- end-- it 'restates to the exact cent, half up' do- price.update!(amount: BigDecimal('19.99'))-- # 19.99 / 1.19 * 1.20 = 20.15798…- expect(gross_for(france)).to eq(BigDecimal('20.16'))- end-- it 'restates a yen price to whole yen' do- yen_price = build(:price, variant: variant, currency: 'JPY', amount: BigDecimal('1000'))-- # 1000 / 1.19 * 1.20 = 1008.403…- expect(yen_price.price_including_vat_for(country: france, market: home_market)).to eq(BigDecimal('1008'))- end- end-- it 'charges the net where the destination levies nothing — a zero-rated export' do- expect(gross_for(japan)).to eq(84.03)- end-- # The rate table is the whole truth only for the built-in engine. Elsewhere an- # absent row means "computed by something that keeps no rows here", not "no tax- # due", so deducting the home VAT would turn every foreign sale into an export.- context 'when the market is on an external tax provider' do- let(:external_market) do- stub_const('SpecExternalTaxProvider', Class.new(Spree::TaxProvider::Base) do- def estimate(*); end- end)- # Market validates tax_provider against the registry.- Spree.tax_providers << SpecExternalTaxProvider-- # Pinned country: the factory pool cycles real codes and can hand out- # Germany, which the home market owns — one country, one market per store.- create(:market, store: store, name: "External #{Time.current.to_f}", currency: 'USD',- default_locale: 'en', tax_provider: 'SpecExternalTaxProvider',- country_codes: %w[US])- end-- after { Spree.tax_providers.delete(SpecExternalTaxProvider) if defined?(SpecExternalTaxProvider) }-- it 'does not restate at all' do- create(:tax_rate, name: 'FR 20% incl', amount: 0.20, tax_category: category,- country_code: france&.iso, included_in_price: true, store: store)-- expect(gross_for(france, market: external_market)).to eq(100.00)- end-- it 'does not turn a rate-less destination into an export' do- expect(gross_for(japan, market: external_market)).to eq(100.00)- end- end-- # The provider estimates against tax_country, which falls back to the market's- # own country, so a cart with no address is still taxed for its destination. The- # price has to follow, or the merchant absorbs the rate difference silently.- describe 'a cart with no shipping address yet' do- let(:french_market) do- create(:market, store: store, name: "France #{Time.current.to_f}", currency: 'USD',- default_locale: 'en', countries: [france])- end-- before do- create(:tax_rate, name: 'FR 20% incl', amount: 0.20, tax_category: category,- country_code: france&.iso, included_in_price: true, store: store)- end-- it 'restates from the market country, keeping the net intact' do- cart = create(:cart, store: store, market: french_market, currency: 'USD')- Spree::Carts::AddItem.call(cart: cart, variant: variant, quantity: 1)-- line_item = cart.line_items.reload.first- expect(cart.tax_address).to be_nil- expect(line_item.price).to eq(100.84)- expect(line_item.pre_tax_amount).to be_within(0.01).of(84.03)- end- end-- describe 'a price the merchant set for the destination' do- let(:french_market) do- create(:market, store: store, name: "France #{Time.current.to_f}", currency: 'USD',- default_locale: 'en', countries: [france])- end-- let(:price_list) do- create(:price_list, store: store).tap do |list|- list.price_rules.create!(type: 'Spree::PriceRules::MarketRule',- preferences: { market_ids: [french_market.id] })- end- end-- let(:list_price) do- create(:price, variant: variant, currency: 'USD', amount: 99, price_list: price_list)- end-- before do- create(:tax_rate, name: 'FR 20% incl', amount: 0.20, tax_category: category,- country_code: france&.iso, included_in_price: true, store: store)- end-- it 'is charged exactly as entered' do- expect(list_price.price_including_vat_for(country: france, market: french_market)).to eq(99.00)- end-- it 'would otherwise have been restated' do- # Same figure on a list with no geographic rule: 99 / 1.19 * 1.20 = 99.83.- plain_list = create(:price_list, store: store)- plain_list.price_rules.create!(type: 'Spree::PriceRules::VolumeRule',- preferences: { min_quantity: 1 })- volume_price = create(:price, variant: variant, currency: 'USD', amount: 99,- price_list: plain_list)-- expect(volume_price.price_including_vat_for(country: france, market: french_market)).to eq(99.83)- end- end- describe 'geographic rules that do not actually narrow' do- let(:french_market) do- create(:market, store: store, name: "France #{Time.current.to_f}", currency: 'USD',- default_locale: 'en', countries: [france])- end-- before do- create(:tax_rate, name: 'FR 20% incl', amount: 0.20, tax_category: category,- country_code: france&.iso, included_in_price: true, store: store)- end-- # A market rule with nothing selected matches everyone, which is the state the- # admin creates it in — it must not switch restatement off for the whole list.- it 'still restates when the market rule names no markets' do- list = create(:price_list, store: store)- list.price_rules.create!(type: 'Spree::PriceRules::MarketRule', preferences: { market_ids: [] })- price = create(:price, variant: variant, currency: 'USD', amount: 95, price_list: list)-- expect(price.final_for_destination?).to be(false)- expect(price.price_including_vat_for(country: france, market: french_market)).to eq(95.80)- end-- # Under 'any' the list can win on the volume rule alone, so the buyer's- # geography is not necessarily why this price applied.- it "still restates a mixed list under the 'any' match policy" do- list = create(:price_list, store: store, match_policy: 'any')- list.price_rules.create!(type: 'Spree::PriceRules::MarketRule',- preferences: { market_ids: [french_market.id] })- list.price_rules.create!(type: 'Spree::PriceRules::VolumeRule', preferences: { min_quantity: 1 })- price = create(:price, variant: variant, currency: 'USD', amount: 90, price_list: list)-- expect(price.final_for_destination?).to be(false)- expect(price.price_including_vat_for(country: france, market: french_market)).to eq(90.76)- end-- it "treats a mixed list under 'all' as final, since every rule matched" do- list = create(:price_list, store: store, match_policy: 'all')- list.price_rules.create!(type: 'Spree::PriceRules::MarketRule',- preferences: { market_ids: [french_market.id] })- list.price_rules.create!(type: 'Spree::PriceRules::VolumeRule', preferences: { min_quantity: 1 })- price = create(:price, variant: variant, currency: 'USD', amount: 90, price_list: list)-- expect(price.final_for_destination?).to be(true)- expect(price.price_including_vat_for(country: france, market: french_market)).to eq(90.00)- end-- it 'applies the same rule to the compare-at price' do- list = create(:price_list, store: store)- list.price_rules.create!(type: 'Spree::PriceRules::MarketRule',- preferences: { market_ids: [french_market.id] })- price = create(:price, variant: variant, currency: 'USD', amount: 90,- compare_at_amount: 120, price_list: list)-- expect(price.compare_at_price_including_vat_for(country: france, market: french_market)).to eq(120.00)- end- end-enddiff --git a/spree/core/spec/models/spree/concerns/vat_price_calculation_spec.rb b/spree/core/spec/models/spree/concerns/vat_price_calculation_spec.rbdeleted file mode 100644index a804a160d3..0000000000--- a/spree/core/spec/models/spree/concerns/vat_price_calculation_spec.rb+++ /dev/null@@ -1,80 +0,0 @@-require 'spec_helper'--module Spree- describe VatPriceCalculation do- let(:test_class) do- Class.new do- include VatPriceCalculation- def total- 10.0- end-- def currency- 'USD'- end- end- end-- describe '#gross_amount' do- subject(:gross_amount) { test_class.new.gross_amount(amount, price_options) }-- # The catalogue is priced including this country's VAT.- let(:home_country) { create(:country, iso: 'DE', name: 'Germany') }- let(:destination) { create(:country, iso: 'FR', name: 'France') }- let(:tax_category) { create(:tax_category) }- let(:price_options) { { country: destination, tax_category: tax_category } }- let(:amount) { 100 }-- context 'with no home country resolvable' do- it 'leaves the price alone' do- # Records first: a tax category needs a store, and this stubs it away.- tax_category- allow(Spree::Current).to receive(:market).and_return(nil)- allow(Spree::Current).to receive(:store).and_return(nil)-- expect(TaxRate).not_to receive(:included_tax_amount_for)- expect(gross_amount).to eq(100)- end- end-- context 'with a home country' do- before { @default_store.default_market.update!(countries: [home_country]) }-- context 'and no destination given' do- let(:price_options) { { tax_category: tax_category } }-- it 'leaves the price alone' do- expect(TaxRate).not_to receive(:included_tax_amount_for)- expect(gross_amount).to eq(100)- end- end-- context 'and the destination is the home country' do- let(:destination) { home_country }-- it 'leaves the price alone — the VAT in it is already the right one' do- expect(TaxRate).not_to receive(:included_tax_amount_for)- expect(gross_amount).to eq(100)- end- end-- context 'and the destination is elsewhere' do- it 'takes the home VAT out and puts the destination VAT on' do- create(:tax_rate, country_code: home_country&.iso, tax_category: tax_category, amount: 0.19,- included_in_price: true)- create(:tax_rate, country_code: destination&.iso, tax_category: tax_category, amount: 0.25,- included_in_price: true)-- # 100 gross at 19% is 84.03 net, which is 105.04 gross at 25%.- expect(gross_amount).to eq(105.04)- end-- it 'reads both rates from the tax configuration' do- expect(TaxRate).to receive(:included_tax_amount_for).twice.and_return(0)- gross_amount- end- end- end- end- end-enddiff --git a/spree/core/spec/models/spree/delivery_rate_spec.rb b/spree/core/spec/models/spree/delivery_rate_spec.rbindex 73479bd674..286217063d 100644--- a/spree/core/spec/models/spree/delivery_rate_spec.rb+++ b/spree/core/spec/models/spree/delivery_rate_spec.rb@@ -23,13 +23,23 @@ describe Spree::DeliveryRate, type: :model docost: 10end+ describe '#tax_inclusive?' do+ it "follows the market of the fulfillment's cart or order" do+ rate = Spree::DeliveryRate.new(fulfillment: shipment, delivery_method: delivery_method, cost: 10)+ allow(shipment.owner).to receive(:tax_inclusive?).and_return(true)++ expect(rate).to be_tax_inclusive+ end+ end+context '#display_price' docontext 'when tax included in price' do+ before { allow(shipping_rate).to receive(:tax_inclusive?).and_return(true) }+let(:default_tax_rate) docreate :tax_rate,name: 'VAT',amount: 0.1,- included_in_price: true,country_code: @default_country&.isoend@@ -57,7 +67,6 @@ describe Spree::DeliveryRate, type: :model docreate :tax_rate,name: 'VAT',amount: 0.2,- included_in_price: true,country_code: create(:country, iso: 'FR', name: 'France')&.isoend@@ -135,9 +144,12 @@ describe Spree::DeliveryRate, type: :model doendcontext 'with tax included in price' do- let(:tax_rate) { create(:tax_rate, amount: 0.1, included_in_price: true) }+ let(:tax_rate) { create(:tax_rate, amount: 0.1) }- before { shipping_rate.tax_rate = tax_rate }+ before do+ shipping_rate.tax_rate = tax_rate+ allow(shipping_rate).to receive(:tax_inclusive?).and_return(true)+ endit 'returns 0' doexpect(shipping_rate.additional_tax_total).to eq(0)@@ -145,7 +157,7 @@ describe Spree::DeliveryRate, type: :model doendcontext 'with tax additional to price' do- let(:tax_rate) { create(:tax_rate, amount: 0.1, included_in_price: false) }+ let(:tax_rate) { create(:tax_rate, amount: 0.1) }before { shipping_rate.tax_rate = tax_rate }@@ -163,9 +175,12 @@ describe Spree::DeliveryRate, type: :model doendcontext 'with tax included in price' do- let(:tax_rate) { create(:tax_rate, amount: 0.1, included_in_price: true) }+ let(:tax_rate) { create(:tax_rate, amount: 0.1) }- before { shipping_rate.tax_rate = tax_rate }+ before do+ shipping_rate.tax_rate = tax_rate+ allow(shipping_rate).to receive(:tax_inclusive?).and_return(true)+ endit 'returns the tax amount' doexpect(shipping_rate.included_tax_total).to eq(shipping_rate.tax_amount)@@ -173,7 +188,7 @@ describe Spree::DeliveryRate, type: :model doendcontext 'with tax additional to price' do- let(:tax_rate) { create(:tax_rate, amount: 0.1, included_in_price: false) }+ let(:tax_rate) { create(:tax_rate, amount: 0.1) }before { shipping_rate.tax_rate = tax_rate }diff --git a/spree/core/spec/models/spree/order/adjustments_spec.rb b/spree/core/spec/models/spree/order/adjustments_spec.rbindex 58ef3510a3..e2924087dc 100644--- a/spree/core/spec/models/spree/order/adjustments_spec.rb+++ b/spree/core/spec/models/spree/order/adjustments_spec.rb@@ -25,7 +25,7 @@ describe Spree::Order doendend- context 'when an order has an taxed shipment with tax included_in_price and apply free_shipping_promotion' do+ context 'when an order has a taxed shipment and applies a free shipping promotion' dolet!(:order) { create(:order) }let!(:line_item) { create(:line_item) }@@ -36,7 +36,6 @@ describe Spree::Order dolet!(:tax_rate) {create(:tax_rate,amount: 0.2,- included_in_price: true,tax_category: tax_category,country_code: country&.iso)diff --git a/spree/core/spec/models/spree/price_rules/market_rule_spec.rb b/spree/core/spec/models/spree/price_rules/market_rule_spec.rbindex 4b4a30f16f..0aa05e1eb1 100644--- a/spree/core/spec/models/spree/price_rules/market_rule_spec.rb+++ b/spree/core/spec/models/spree/price_rules/market_rule_spec.rb@@ -66,19 +66,4 @@ describe Spree::PriceRules::MarketRule, type: :model doexpect(rule.markets).to be_emptyendend- describe '#geographic?' do- # A list narrowed by geography states its prices for that geography, so they- # are charged as entered rather than restated for the buyer's VAT.- it 'is true once markets are named' do- rule = described_class.new(price_list: price_list)- rule.preferred_market_ids = [market.id]-- expect(rule.geographic?).to be(true)- end-- # An empty list matches every buyer, so it narrows nothing.- it 'is false while no market is named' do- expect(described_class.new(price_list: price_list).geographic?).to be(false)- end- endenddiff --git a/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb b/spree/core/spec/models/spree/price_rules/volume_rule_spec.rbindex e15f6a4f4f..062c73807a 100644--- a/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb+++ b/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb@@ -43,10 +43,4 @@ describe Spree::PriceRules::VolumeRule, type: :model doexpect(rule.applicable?(context)).to be falseendend- describe '#geographic?' do- it 'is false' do- # Narrowed by quantity, not by a country — its prices still restate.- expect(described_class.new.geographic?).to be(false)- end- endenddiff --git a/spree/core/spec/models/spree/price_spec.rb b/spree/core/spec/models/spree/price_spec.rbindex 659e3d354b..fd2d6f4c2d 100644--- a/spree/core/spec/models/spree/price_spec.rb+++ b/spree/core/spec/models/spree/price_spec.rb@@ -277,101 +277,15 @@ describe Spree::Price, type: :model doenddescribe '#price_including_vat_for' do- subject(:price_with_vat) { price.price_including_vat_for(price_options) }+ let(:price) { build(:price, amount: 10, compare_at_amount: 100) }- let(:variant) { create(:variant) }- let(:home_country) { Spree::Country.new(iso: 'DE') }- let(:destination) { Spree::Country.new(iso: 'FR') }- let(:amount) { 10 }- let(:tax_category) { Spree::TaxCategory.new }- let(:price) { build :price, variant: variant, amount: amount }- let(:price_options) { { country: destination } }-- context 'when the destination is another country' do- before do- allow(variant).to receive(:tax_category).and_return(tax_category)- expect(price).to receive(:default_tax_country).at_least(:once).and_return(home_country)- allow(price).to receive(:included_tax_amount).with({ country: home_country, tax_category: tax_category }).and_return(0.19)- allow(price).to receive(:included_tax_amount).with({ country: destination, tax_category: tax_category }).and_return(0.25)- end-- it 'returns the correct price including another VAT to two digits' do- expect(price_with_vat).to eq(10.50)- end- end-- context 'when the destination is the home country' do- before do- allow(variant).to receive(:tax_category).and_return(tax_category)- expect(price).to receive(:default_tax_country).at_least(:once).and_return(destination)- end-- it 'returns the correct price' do- expect(price).to receive(:price).and_call_original- expect(price_with_vat).to eq(10.00)- end- end-- context 'when no home country is set' do- before do- allow(variant).to receive(:tax_category).and_return(tax_category)- expect(price).to receive(:default_tax_country).at_least(:once).and_return(nil)- end-- it 'returns the correct price' do- expect(price).to receive(:price).and_call_original- expect(price.price_including_vat_for(country: destination)).to eq(10.00)- end- end- end-- describe '#compare_at_price_including_vat_for' do- subject(:compare_at_price_with_vat) { price.compare_at_price_including_vat_for(price_options) }-- let(:variant) { create(:variant) }- let(:home_country) { Spree::Country.new(iso: 'DE') }- let(:destination) { Spree::Country.new(iso: 'FR') }- let(:amount) { 10 }- let(:compare_at_amount) { 100 }- let(:tax_category) { Spree::TaxCategory.new }- let(:price) { build :price, variant: variant, amount: amount, compare_at_amount: compare_at_amount }- let(:price_options) { { country: destination } }-- context 'when the destination is another country' do- before do- allow(variant).to receive(:tax_category).and_return(tax_category)- expect(price).to receive(:default_tax_country).at_least(:once).and_return(home_country)- allow(price).to receive(:included_tax_amount).with({ country: home_country, tax_category: tax_category }).and_return(0.19)- allow(price).to receive(:included_tax_amount).with({ country: destination, tax_category: tax_category }).and_return(0.25)- end-- it 'returns the correct price including another VAT to two digits' do- expect(compare_at_price_with_vat).to eq(105.04)- end- end+ it 'returns the price as entered for a buyer abroad' do+ allow(Spree::Deprecation).to receive(:warn)+ france = Spree::Country.by_iso('FR')- context 'when the destination is the home country' do- before do- allow(variant).to receive(:tax_category).and_return(tax_category)- expect(price).to receive(:default_tax_country).at_least(:once).and_return(destination)- end-- it 'returns the correct price' do- expect(price).to receive(:compare_at_price).and_call_original- expect(compare_at_price_with_vat).to eq(100.00)- end- end-- context 'when no home country is set' do- before do- allow(variant).to receive(:tax_category).and_return(tax_category)- expect(price).to receive(:default_tax_country).at_least(:once).and_return(nil)- end-- it 'returns the correct price' do- expect(price).to receive(:compare_at_price).and_call_original- expect(price.compare_at_price_including_vat_for(country: destination)).to eq(100.00)- end+ expect(price.price_including_vat_for(country: france)).to eq(10)+ expect(price.compare_at_price_including_vat_for(country: france)).to eq(100)+ expect(Spree::Deprecation).to have_received(:warn).twiceendend@@ -539,38 +453,6 @@ describe Spree::Price, type: :model doendendend- describe '#final_for_destination?' do- let(:store) { @default_store }- let(:variant) { create(:variant) }-- it 'is true for a price on a list narrowed by market' do- market = create(:market, store: store, name: "M #{Time.current.to_f}", currency: 'USD',- default_locale: 'en')- list = create(:price_list, store: store)- list.price_rules.create!(type: 'Spree::PriceRules::MarketRule',- preferences: { market_ids: [market.id] })-- price = create(:price, variant: variant, currency: 'USD', amount: 99, price_list: list)-- expect(price.final_for_destination?).to be(true)- end-- it 'is false for a price on a list narrowed by something other than geography' do- list = create(:price_list, store: store)- list.price_rules.create!(type: 'Spree::PriceRules::VolumeRule',- preferences: { min_quantity: 1 })-- price = create(:price, variant: variant, currency: 'USD', amount: 99, price_list: list)-- expect(price.final_for_destination?).to be(false)- end-- it 'is false for a base price' do- base = variant.prices.find_by(currency: 'USD', price_list_id: nil)-- expect(base.final_for_destination?).to be(false)- end- end# The single-row writers reach the same rule the bulk path enforces over a# whole batch — the admin price endpoints write through the modeldiff --git a/spree/core/spec/models/spree/pricing_provider_spec.rb b/spree/core/spec/models/spree/pricing_provider_spec.rbindex 3d662d30e1..770f51e7c2 100644--- a/spree/core/spec/models/spree/pricing_provider_spec.rb+++ b/spree/core/spec/models/spree/pricing_provider_spec.rb@@ -70,9 +70,9 @@ RSpec.describe 'Pricing providers' doexpect { price.save }.to raise_error(ActiveRecord::ReadOnlyRecord)end- # The contract does not require a provider to set the variant, and the- # tax-inclusive restatement reads it — without this the price fails deep- # inside that call with an obscure NoMethodError.+ # The contract does not require a provider to set the variant, and+ # everything downstream reads it — without this the price fails far from+ # the provider with an obscure NoMethodError.it 'fills in the variant when a provider builds a price without one' dobare = Class.new(Spree::PricingProvider::Base) dodef self.key = 'bare'diff --git a/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb b/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rbindex b6f4c375f2..7c527c8610 100644--- a/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb+++ b/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb@@ -69,7 +69,7 @@ describe 'Promotion discounts and the taxable basis', type: :model docontext 'with additional (US-style) tax of 10%' dolet(:item_price) { 250 }let!(:tax_rate) do- create(:tax_rate, country_code: @default_country&.iso, tax_category: tax_category, amount: 0.10, included_in_price: false)+ create(:tax_rate, country_code: @default_country&.iso, tax_category: tax_category, amount: 0.10)endbefore { build_cart! }@@ -157,10 +157,13 @@ describe 'Promotion discounts and the taxable basis', type: :model docontext 'with included (VAT-style) tax of 20%' dolet(:item_price) { 350 }let!(:tax_rate) do- create(:tax_rate, country_code: @default_country&.iso, tax_category: tax_category, amount: 0.20, included_in_price: true)+ create(:tax_rate, country_code: @default_country&.iso, tax_category: tax_category, amount: 0.20)end- before { build_cart! }+ before do+ store.default_market.update!(tax_inclusive: true)+ build_cart!+ endit 'starts from VAT on the full amount' doexpect(order.included_tax_total).to eq(58.33)diff --git a/spree/core/spec/models/spree/stock/estimator_spec.rb b/spree/core/spec/models/spree/stock/estimator_spec.rbindex 1c629712e6..e5ae201691 100644--- a/spree/core/spec/models/spree/stock/estimator_spec.rb+++ b/spree/core/spec/models/spree/stock/estimator_spec.rb@@ -247,72 +247,26 @@ module Spreeendend- context 'VAT price calculation' do+ # The cost is charged as quoted wherever the parcel goes; whether its+ # tax sits inside it is the market's choice (DeliveryRate#tax_amount).+ context 'when the order ships to another country that charges VAT' dolet(:tax_category) { create :tax_category }let!(:shipping_method) { create(:delivery_method, tax_category: tax_category) }-- # Shipping is priced including the home country's VAT.- let(:home_country) { order.tax_address.country }- let!(:default_vat) do+ let(:other_country) { create(:country, iso: 'FR', name: 'France') }+ let!(:other_vat) docreate :tax_rate,- included_in_price: true,- country_code: home_country&.iso,- amount: 0.2,+ country_code: other_country&.iso,+ amount: 0.3,tax_category: shipping_method.tax_categoryend- before { @default_store.default_market.update!(countries: [home_country]) }-- context 'when the order has no address to tax against' do- before { allow(order).to receive(:tax_address).and_return nil }-- it_behaves_like 'shipping rate matches'- end-- context 'when the order ships within the home country' do- it_behaves_like 'shipping rate matches'- end-- context 'when the order ships to a country with no VAT' do- let(:country_without_vat) { create(:country, iso: 'IN', name: 'India') }-- before do- allow(order).to receive(:tax_address).- and_return(create(:address, country: country_without_vat, state: nil,- state_name: 'Delhi', zipcode: '110001'))- end-- it 'deducts the home VAT from the cost' do- delivery_rates = subject.delivery_rates(package)- # deduct default vat: 4.00 / 1.2 = 3.33 (rounded)- expect(delivery_rates.first.cost).to eq(3.33)- end+ before do+ allow(order).to receive(:tax_address).+ and_return(create(:address, country: other_country, state: nil,+ state_name: 'Paris', zipcode: '75001'))end- context 'when the order ships to another country that charges VAT' do- let(:other_country) { create(:country, iso: 'FR', name: 'France') }- let!(:other_vat) do- create :tax_rate,- included_in_price: true,- country_code: other_country&.iso,- amount: 0.3,- tax_category: shipping_method.tax_category- end-- before do- allow(order).to receive(:tax_address).- and_return(create(:address, country: other_country, state: nil,- state_name: 'Paris', zipcode: '75001'))- end-- it 'deducts the home vat and applies the foreign vat to calculate the price' do- delivery_rates = subject.delivery_rates(package)- #- # deduct default vat: 4.00 / 1.2 = 3.33 (rounded)- # apply foreign vat: 3.33 * 1.3 = 4.33 (rounded)- expect(delivery_rates.first.cost).to eq(4.33)- end- end+ it_behaves_like 'shipping rate matches'endenddiff --git a/spree/core/spec/models/spree/tax_provider/internal_spec.rb b/spree/core/spec/models/spree/tax_provider/internal_spec.rbindex 7442134093..e5a76f99cf 100644--- a/spree/core/spec/models/spree/tax_provider/internal_spec.rb+++ b/spree/core/spec/models/spree/tax_provider/internal_spec.rb@@ -10,7 +10,7 @@ describe Spree::TaxProvider::Internal, type: :model dodescribe '#estimate' docontext 'with an additional rate' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: line_item.tax_category, included_in_price: false) }+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: line_item.tax_category) }it 'writes a tax line with snapshots' doprovider.estimate(order)@@ -65,21 +65,30 @@ describe Spree::TaxProvider::Internal, type: :model doendend- context 'with an included (VAT) rate' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.2, tax_category: line_item.tax_category, included_in_price: true) }+ context 'when the prices include tax' do+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.2, tax_category: line_item.tax_category) }it 'backs the tax out of the gross basis' do- provider.estimate(order)+ provider.estimate(order, tax_inclusive: true)tax_line = order.tax_lines.reload.soleexpect(tax_line.amount).to eq(1.67)expect(tax_line.included).to be(true)+ expect(tax_line.label).to eq("#{rate.name} 20% (Included in Price)")expect(line_item.reload.pre_tax_amount.round(2)).to eq(8.33)end++ it "reads the setting from the order's market when the caller leaves it out" do+ allow(order).to receive(:tax_inclusive?).and_return(true)++ provider.estimate(order)++ expect(order.tax_lines.reload.sole).to have_attributes(amount: 1.67, included: true)+ endendcontext 'with a matched zero rate' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0, tax_category: line_item.tax_category, included_in_price: false) }+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0, tax_category: line_item.tax_category) }it 'still writes a row, marked zero-rated' doprovider.estimate(order)@@ -92,7 +101,7 @@ describe Spree::TaxProvider::Internal, type: :model doendcontext 'with no matching rate' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: create(:tax_category), included_in_price: false) }+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: create(:tax_category)) }it 'writes nothing, having formed no opinion' doprovider.estimate(order)@@ -106,7 +115,7 @@ describe Spree::TaxProvider::Internal, type: :model dolet(:cart_line_item) { cart.line_items.first }let(:cart_country) { cart.tax_address.country }let!(:rate) do- create(:tax_rate, country_code: cart_country&.iso, amount: 0.1, tax_category: cart_line_item.tax_category, included_in_price: false)+ create(:tax_rate, country_code: cart_country&.iso, amount: 0.1, tax_category: cart_line_item.tax_category)endit 'owns the row through the cart FK' do@@ -120,7 +129,7 @@ describe Spree::TaxProvider::Internal, type: :model doendcontext 'with an exemption covering the sale' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: line_item.tax_category, included_in_price: false) }+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: line_item.tax_category) }let(:exemption) { Spree::TaxExemption.new(reason_code: 'resale', certificate_number: 'CERT-1') }it 'writes a zero row recording the claim' do@@ -155,7 +164,7 @@ describe Spree::TaxProvider::Internal, type: :model do# The whole chain: a certificate the company holds, resolved by the real# service, reaching the provider as a claim.context 'with a certificate the buyer company holds' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: line_item.tax_category, included_in_price: false) }+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: line_item.tax_category) }let(:company) { create(:company, store: @default_store) }before { order.update!(company: company) }@@ -186,11 +195,11 @@ describe Spree::TaxProvider::Internal, type: :model doendend- context 'with an exemption against an included (VAT) rate' do- let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.2, tax_category: line_item.tax_category, included_in_price: true) }+ context 'with an exemption when the prices include tax' do+ let!(:rate) { create(:tax_rate, country_code: country&.iso, amount: 0.2, tax_category: line_item.tax_category) }it 'leaves the whole basis pre-tax, having no tax to back out' do- provider.estimate(order, exemptions: [Spree::TaxExemption.new(reason_code: 'government')])+ provider.estimate(order, exemptions: [Spree::TaxExemption.new(reason_code: 'government')], tax_inclusive: true)expect(order.tax_lines.reload.sole.amount).to eq(0)expect(line_item.reload.pre_tax_amount).to eq(10)@@ -200,7 +209,7 @@ describe Spree::TaxProvider::Internal, type: :model docontext 'when another store holds the default tax category' dolet!(:rate) docreate(:tax_rate, country_code: country&.iso, amount: 0.1,- tax_category: create(:tax_category, is_default: true), included_in_price: false)+ tax_category: create(:tax_category, is_default: true))endlet!(:fee) { create(:fee, order: order, amount: 5, kind: 'surcharge', label: 'Handling') }@@ -228,13 +237,13 @@ describe Spree::TaxProvider::Internal, type: :model do# recalculate the order and estimate tax a second time.fulfillment.update_columns(cost: 10)# A store default exists, so falling back to it is a visible wrong answer.- create(:tax_rate, country_code: country&.iso, amount: 0.2, included_in_price: false,+ create(:tax_rate, country_code: country&.iso, amount: 0.2,tax_category: create(:tax_category, is_default: true))fulfillment.reloadendit "taxes delivery at its delivery method's category" do- reduced_rate = create(:tax_rate, country_code: country&.iso, amount: 0.05, included_in_price: false,+ reduced_rate = create(:tax_rate, country_code: country&.iso, amount: 0.05,tax_category: reduced_rate_category)provider.estimate(order, [fulfillment])@@ -257,7 +266,7 @@ describe Spree::TaxProvider::Internal, type: :model docontext 'with a taxable fee' dolet!(:rate) do- create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: create(:tax_category, is_default: true), included_in_price: false)+ create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: create(:tax_category, is_default: true))endlet!(:fee) { create(:fee, order: order, amount: 5, kind: 'surcharge', label: 'Handling') }@@ -272,7 +281,7 @@ describe Spree::TaxProvider::Internal, type: :model docontext 'with a customs duty' dolet!(:rate) do- create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: create(:tax_category, is_default: true), included_in_price: false)+ create(:tax_rate, country_code: country&.iso, amount: 0.1, tax_category: create(:tax_category, is_default: true))endlet!(:duty) { create(:fee, order: order, amount: 20, kind: 'duty', label: 'Import duty') }@@ -413,11 +422,11 @@ describe Spree::TaxProvider::Internal, type: :model dolet(:line) { exchange.exchange_line_items.first }let!(:rate) docreate(:tax_rate, country_code: order.tax_address.country.iso, amount: 0.2,- tax_category: line.new_variant.tax_category, included_in_price: true)+ tax_category: line.new_variant.tax_category)endit 'taxes the replacement as a sale of its own' do- provider.estimate_replacement(order, [line])+ provider.estimate_replacement(order, [line], tax_inclusive: true)row = line.tax_lines.charges.soleexpect(row.amount).to eq((line.taxable_basis / 1.2 * 0.2).round(2))diff --git a/spree/core/spec/models/spree/tax_provider/service_tax_rate_spec.rb b/spree/core/spec/models/spree/tax_provider/service_tax_rate_spec.rbindex c2fcab15b0..840b2df46c 100644--- a/spree/core/spec/models/spree/tax_provider/service_tax_rate_spec.rb+++ b/spree/core/spec/models/spree/tax_provider/service_tax_rate_spec.rb@@ -19,14 +19,14 @@ RSpec.describe 'Spree::TaxProvider service tax rate' doit 'reads the rate configured for where the business sits' docreate(:tax_rate, store: store, tax_category: category, amount: 0.19,- country_code: 'DE', included_in_price: false)+ country_code: 'DE')expect(provider.service_tax_rate(address: address, store: store)).to eq(0.19)endit 'has no opinion when nothing is configured for that jurisdiction' docreate(:tax_rate, store: store, tax_category: category, amount: 0.19,- country_code: 'FR', included_in_price: false)+ country_code: 'FR')expect(provider.service_tax_rate(address: address, store: store)).to be_nilend@@ -35,20 +35,11 @@ RSpec.describe 'Spree::TaxProvider service tax rate' doexpect(provider.service_tax_rate(address: nil, store: store)).to be_nilend- # A commission is quoted net and its VAT is added on top, so a rate- # describing tax-inclusive consumer pricing does not describe this supply.- it 'ignores rates configured as included in the price' do- create(:tax_rate, store: store, tax_category: category, amount: 0.19,- country_code: 'DE', included_in_price: true)-- expect(provider.service_tax_rate(address: address, store: store)).to be_nil- end-it 'does not read another store rates' doother_store = create(:store)other_category = create(:tax_category, store: other_store, is_default: true)create(:tax_rate, store: other_store, tax_category: other_category, amount: 0.19,- country_code: 'DE', included_in_price: false)+ country_code: 'DE')expect(provider.service_tax_rate(address: address, store: store)).to be_nilenddiff --git a/spree/core/spec/models/spree/tax_rate_spec.rb b/spree/core/spec/models/spree/tax_rate_spec.rbindex 117a29a946..ac41372f45 100644--- a/spree/core/spec/models/spree/tax_rate_spec.rb+++ b/spree/core/spec/models/spree/tax_rate_spec.rb@@ -84,8 +84,9 @@ describe Spree::TaxRate, type: :model doenddescribe 'estimating through the tax provider' do- # The EU one-stop-shop case: a catalogue priced gross in the store's own- # country, restated for a customer taxed somewhere else.+ # The EU one-stop-shop case: a catalogue priced gross for a market of+ # several countries. Every customer pays the price as entered, with their+ # own country's tax inside it.context 'for MOSS taxation in Europe' dolet(:germany) { create(:country, iso: 'DE', name: 'Germany') }let(:france) { create(:country, iso: 'FR', name: 'France') }@@ -96,30 +97,30 @@ describe Spree::TaxRate, type: :model dolet!(:german_vat) docreate(:tax_rate, name: 'German VAT', amount: 0.19, tax_category: moss_category,- country_code: germany&.iso, included_in_price: true)+ country_code: germany&.iso)endlet!(:french_vat) docreate(:tax_rate, name: 'French VAT', amount: 0.25, tax_category: moss_category,- country_code: france&.iso, included_in_price: true)+ country_code: france&.iso)end# Physical goods are taxed where they ship from, so both EU countries# carry the same rate — one row each, a zone spanning both being gone.let!(:german_goods_vat) docreate(:tax_rate, name: 'EU VAT (DE)', amount: 0.19, tax_category: normal_category,- country_code: germany&.iso, included_in_price: true)+ country_code: germany&.iso)endlet!(:french_goods_vat) docreate(:tax_rate, name: 'EU VAT (FR)', amount: 0.19, tax_category: normal_category,- country_code: france&.iso, included_in_price: true)+ country_code: france&.iso)endlet(:download) { create(:product, tax_category: moss_category, price: 100) }let(:tshirt) { create(:product, tax_category: normal_category, price: 100) }let(:order) { create(:order, ship_address: nil, bill_address: nil) }- # Prices are quoted including German VAT — the market being browsed is- # Germany, which is where the store's own country comes from.- before { @default_store.default_market.update!(countries: [germany]) }+ # Before an address the market's first country is the tax country, which+ # is Germany here.+ before { @default_store.default_market.update!(countries: [germany], tax_inclusive: true) }ZIPCODES = { 'DE' => '10115', 'FR' => '75001', 'IN' => '110001' }.freeze@@ -151,19 +152,19 @@ describe Spree::TaxRate, type: :model doexpect(order.included_tax_total).to eq(15.97)end- it 'to france costs more including tax' do+ it 'to france costs 100 euros with French tax inside it' doship_to(france)order.recalculate_totals!- expect(order.display_total).to eq(Spree::Money.new(105.04))- expect(order.included_tax_total).to eq(21.01)+ expect(order.display_total).to eq(Spree::Money.new(100))+ expect(order.included_tax_total).to eq(20)expect(order.additional_tax_total).to eq(0)end- it 'to somewhere else costs the net amount' do+ it 'to somewhere untaxed costs 100 euros with no tax' doship_to(india)order.recalculate_totals!expect(order.included_tax_total).to eq(0)- expect(order.display_total).to eq(Spree::Money.new(84.03))+ expect(order.display_total).to eq(Spree::Money.new(100))endend@@ -185,11 +186,11 @@ describe Spree::TaxRate, type: :model doexpect(order.additional_tax_total).to eq(0)end- it 'to somewhere else costs the net amount' do+ it 'to somewhere untaxed costs 100 euros with no tax' doship_to(india)order.recalculate_totals!expect(order.included_tax_total).to eq(0)- expect(order.display_total).to eq(Spree::Money.new(84.03))+ expect(order.display_total).to eq(Spree::Money.new(100))endendend@@ -223,51 +224,6 @@ describe Spree::TaxRate, type: :model doendend- describe '.included_tax_amount_for' do- subject(:included_tax_amount) { Spree::TaxRate.included_tax_amount_for(price_options) }-- let!(:order) { create :order_with_line_items }- let(:line_item) { order.line_items.first }- let(:country) { order.tax_address.country }-- let!(:included_tax_rate) do- create(:tax_rate, included_in_price: true, tax_category: line_item.tax_category,- country_code: country&.iso, amount: 0.4)- end- let!(:other_included_tax_rate) do- create(:tax_rate, included_in_price: true, tax_category: line_item.tax_category,- country_code: country&.iso, amount: 0.05)- end- # Additional tax is added to the price rather than sitting inside it.- let!(:additional_tax_rate) do- create(:tax_rate, included_in_price: false, tax_category: line_item.tax_category,- country_code: country&.iso, amount: 0.2)- end- let!(:included_tax_rate_from_somewhere_else) do- create(:tax_rate, included_in_price: true, tax_category: line_item.tax_category,- country_code: create(:country, iso: 'JP', name: 'Japan')&.iso, amount: 0.1)- end-- let(:price_options) { { country: country, tax_category: line_item.tax_category } }-- it 'sums only the included rates of that jurisdiction' do- expect(included_tax_amount).to eq(0.45)- end-- it 'accepts an address instead of a country' do- expect(described_class.included_tax_amount_for(address: order.tax_address,- tax_category: line_item.tax_category)).to eq(0.45)- end-- it 'is zero without a jurisdiction' do- expect(described_class.included_tax_amount_for(tax_category: line_item.tax_category)).to eq(0)- end-- it 'is zero without a tax category' do- expect(described_class.included_tax_amount_for(country: country)).to eq(0)- end- end-describe '#adjustment_label' doit 'returns the name and amount for the tax rate' dotax_rate = Spree::TaxRate.new(name: 'Sales Tax', amount: 0.1)@@ -278,6 +234,11 @@ describe Spree::TaxRate, type: :model dotax_rate = Spree::TaxRate.new(name: 'Sales Tax', amount: 0)expect(tax_rate.adjustment_label).to eq('Sales Tax')end++ it 'says so when the tax is inside the price' do+ tax_rate = Spree::TaxRate.new(name: 'VAT', amount: 0.2)+ expect(tax_rate.adjustment_label(included: true)).to eq('VAT 20% (Included in Price)')+ endenddescribe 'percentage conversion' dodiff --git a/spree/core/spec/workflows/spree/carts/add_item_spec.rb b/spree/core/spec/workflows/spree/carts/add_item_spec.rbindex d3c797e73c..e837890368 100644--- a/spree/core/spec/workflows/spree/carts/add_item_spec.rb+++ b/spree/core/spec/workflows/spree/carts/add_item_spec.rb@@ -87,11 +87,12 @@ module SpreeSpree::TaxRate.create(name: 'Tax Rate 1',amount: 0.25,- included_in_price: true,tax_category: category,country_code: @default_country&.iso)end++ before { cart.market.update!(tax_inclusive: true) }let(:variant) { create(:variant, price: 1000) }let(:calculator) { Spree::Calculator::PercentOnLineItem.new(preferred_percent: 50) }let!(:action) { Spree::Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }diff --git a/spree/core/spec/workflows/spree/carts/complete_spec.rb b/spree/core/spec/workflows/spree/carts/complete_spec.rbindex 6f9ade7569..a78436ab8f 100644--- a/spree/core/spec/workflows/spree/carts/complete_spec.rb+++ b/spree/core/spec/workflows/spree/carts/complete_spec.rb@@ -266,7 +266,7 @@ module Spreelet(:tax_category) { create(:tax_category) }let!(:rate) docreate(:tax_rate, store: store, country_code: ready_cart.tax_country&.iso, amount: 0.1,- included_in_price: false, tax_category: tax_category)+ tax_category: tax_category)endbefore do@@ -322,7 +322,7 @@ module Spreebefore dodefault_category = create(:tax_category, store: store, is_default: true)create(:tax_rate, store: store, country_code: ready_cart.tax_country&.iso, amount: 0.2,- included_in_price: false, tax_category: default_category)+ tax_category: default_category)create(:fee, order: nil, cart: ready_cart, amount: 9, kind: 'payment', label: 'Card surcharge')ready_cart.reload.recalculate_totals!ready_cart.payments.first.update!(amount: ready_cart.reload.total)diff --git a/spree/core/spec/workflows/spree/carts/complete_split_spec.rb b/spree/core/spec/workflows/spree/carts/complete_split_spec.rbindex bcf5c03c59..c5a3ce5558 100644--- a/spree/core/spec/workflows/spree/carts/complete_split_spec.rb+++ b/spree/core/spec/workflows/spree/carts/complete_split_spec.rb@@ -264,7 +264,7 @@ module Spreelet!(:tax_category) { create(:tax_category, store: store, is_default: true) }let!(:tax_rate) docreate(:tax_rate, store: store, country_code: cart.tax_country&.iso, amount: 0.2,- included_in_price: false, tax_category: tax_category)+ tax_category: tax_category)endlet(:cart) do@@ -398,7 +398,7 @@ module Spreebefore docreate(:tax_rate, store: store, country_code: cart.tax_country&.iso, amount: 0.2,- included_in_price: false, tax_category: tax_category)+ tax_category: tax_category)create(:fee, order: nil, cart: cart, amount: 9, kind: 'payment', label: 'Card surcharge')cart.reload.recalculate_totals!cart.payments.each { |payment| payment.update!(amount: cart.reload.total) }@@ -439,7 +439,7 @@ module Spreebefore docreate(:tax_rate, store: store, country_code: cart.tax_country&.iso, amount: 0.2,- included_in_price: false, tax_category: tax_category)+ tax_category: tax_category)create(:fee, order: nil, cart: cart, line_item: cart.line_items.reload.last,amount: 10, kind: 'gift_wrap', label: 'Gift wrap')cart.reload.recalculate_totals!@@ -475,7 +475,7 @@ module Spreebefore docreate(:tax_rate, store: store, country_code: cart.tax_country&.iso, amount: 0.2,- included_in_price: false, tax_category: tax_category)+ tax_category: tax_category)create(:fee, order: nil, cart: cart, fulfillment: cart.fulfillments.first,amount: 10, kind: 'handling', label: 'Handling')cart.reload.recalculate_totals!diff --git a/spree/core/spec/workflows/spree/exchanges/lifecycle_spec.rb b/spree/core/spec/workflows/spree/exchanges/lifecycle_spec.rbindex 18ff1afd98..36b084c771 100644--- a/spree/core/spec/workflows/spree/exchanges/lifecycle_spec.rb+++ b/spree/core/spec/workflows/spree/exchanges/lifecycle_spec.rb@@ -240,7 +240,7 @@ RSpec.describe 'Spree::Exchanges workflows' docreate(:tax_line, order: order, line_item: line_item, amount: 2.5, rate: 0.1, label: 'Sales tax 10%')order.recalculate_totals!create(:tax_rate, country_code: order.tax_address.country.iso, amount: 0.1,- tax_category: replacement.tax_category, included_in_price: false)+ tax_category: replacement.tax_category)order.payments.completed.first.update_column(:amount, 500)replacement.stock_levels.first&.set_count_on_hand(10)allow_any_instance_of(Spree::Refund).to receive(:perform!).and_return(true)