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
Revert the BusinessAddress STI conversion
Damian Legawiecfab8996d758d
diff --git a/docs/plans/6.0-multi-vendor-marketplace.md b/docs/plans/6.0-multi-vendor-marketplace.mdindex 60d31f3b00..156400fe1d 100644--- a/docs/plans/6.0-multi-vendor-marketplace.md+++ b/docs/plans/6.0-multi-vendor-marketplace.md@@ -241,7 +241,7 @@ Core already models exactly this. `Spree::TaxIdentifier` (from `6.0-tax-provider**No per-seller tax rate.** Adding one is the legacy `platform_fee_tax_rate` column this plan already rejected (Resolved Decisions, 2026-06-16): the seller supplies tax *identity*, and the commission tax *rate* resolves through `CommissionRate` + the `TaxProvider` so it stays jurisdiction-correct.-**One `Address` subclass, real STI, universal (2026-08-22 — supersedes the no-type-column position taken earlier the same day).** The legacy module subclassed `BillingAddress`/`ReturnsAddress` to override `require_name?` (a company address has no first and last name) and `show_company_address_field?`. Returns no longer need an address subclass at all — they route to a stock location — so only the billing half survives, as `Spree::BusinessAddress`, and it is not seller-only: company locations' addresses are business addresses too, and B2B checkout will put one on a cart. That is what settled STI over table-sharing — the rules must travel with the row. A company address copied onto a cart's base-typed `bill_address` loads back as a `BusinessAddress` and validates as one (company required, no personal name) without checkout knowing anything about it, which a class chosen by the owning association cannot do. `spree_addresses` gains a `type` column (nullable; plain rows stay NULL and load as `Spree::Address`); `empty?` excludes it, and value comparison/dedup keep it — same postal facts under different rules are different addresses, and `check` never merges a business address into a personal twin. A `CompanyLocation` stamps its own company's name onto an address payload that lacks one, so API clients aren't made to repeat what the branch already knows.+**One `Address` subclass, sharing the table.** The legacy module subclassed `BillingAddress`/`ReturnsAddress` to override `require_name?` (a company address has no first and last name) and `show_company_address_field?`. Returns no longer need an address subclass at all — they route to a stock location — so only the billing half survives, as `Spree::BusinessAddress`. It is **not** STI: `spree_addresses` has no `type` column and gains none. STI was implemented and reverted (decisions.md 2026-08-23) — checkout copies address *attributes*, not records (`update_or_create_address` ends at `Spree::Address.create`), so the class never survives the copy that was the whole argument for it; keeping `type` significant for dedup would stop a B2B buyer's address book from ever matching; and the tax decision reads the owner (`company_location_id`, then Company) and never the address class. The base `Address` has carried a `company` column and preference-driven `require_company?` all along. The subclass reads the same rows and overrides the three predicates (`require_name?` false, `require_company?` true, `show_company_address_field?` true), which is where those rules belong — the alternative tried first was a `before_validation` flag on the seller, and a validation rule that has to be switched on per record is a class.**Supersedes** the `belongs_to :returns_address` line in the Seller model sketch below, and the `Spree::SellerRequirements::ReturnsAddress` checklist kind becomes "has a returns location".@@ -743,7 +743,7 @@ Even before this lands, work touching adjacent areas should:- **Tax provider (`6.0-tax-provider.md`)** and **Delivery rate provider (`6.0-delivery-rate-provider.md`)**: the `PayoutProvider` follows the same pluggable-strategy shape — keep the provider-registration convention consistent so all three (tax, delivery rate, payout) register and resolve the same way.- **Admin API (`6.0-admin-api.md`)**: the `Seller` prefix is `sel_`. The "Marketplace (new in 6.0)" endpoint group there is the *operator's* API surface — keep it in sync. Seller users never call the Admin API (Decision 10).- **Auth + RBAC (`6.0-platform-auth.md`, `6.0-admin-rbac.md`)**: no third principal — never add a `SellerUser`/`Spree.seller_user_class`; seller staff are `Spree.admin_user_class`. Never derive back-office membership from `store_id` alone — match `RoleUser.resource_type` (`Ability#staff_roles` and `RoleGrantGuard` already do; the membership check must follow). New login surfaces get their own strategy registry and JWT audience; refresh tokens must carry the audience they were minted for. Catalog resources that sellers may hold must be marked seller-grantable at `register_resource`; `settings`/`staff`/`api_keys` never are. Seller-branch controllers scope-fetch through `current_seller` and never subclass admin controllers.-- **Seller addresses (Decision 12)**: do not add a `returns_address` back, and do not give a seller a tax *rate* column — identity (`legal_name`, `registration_number`, a `TaxIdentifier`) is the seller's, the rate is `CommissionRate` + `TaxProvider`. A billing address is a `Spree::BusinessAddress` (real STI since 2026-08-22; company locations' addresses are the same class). Code reading a seller's returns destination goes through `Seller#returns_location`, never a stored address FK. `StockLocation` name-uniqueness and its `default` flag are per-owner, so new code must not assume one default per store.+- **Seller addresses (Decision 12)**: do not add a `returns_address` back, and do not give a seller a tax *rate* column — identity (`legal_name`, `registration_number`, a `TaxIdentifier`) is the seller's, the rate is `CommissionRate` + `TaxProvider`. A billing address is a `Spree::BusinessAddress` (table-sharing subclass, never STI — before proposing a `type` column again, read decisions.md 2026-08-23: `update_or_create_address` and `find_existing_address` are what decide it). Code reading a seller's returns destination goes through `Seller#returns_location`, never a stored address FK. `StockLocation` name-uniqueness and its `default` flag are per-owner, so new code must not assume one default per store.- Do **not** revive the legacy commission model's shape (label-based rows + denormalized fee totals on the order), do **not** model commission as a polymorphic `Adjustment`, and do **not** write commission as a `Spree::Fee` (fees are buyer-facing and roll into order totals — Decision 2) — 6.0 uses the off-order `Spree::CommissionLine` ledger. Do **not** put the fund ledger in a payment-gateway namespace (the legacy gateway-namespaced-transfer mistake) nor collapse transfer and payout into one model — `Spree::SellerTransfer` (on-fulfillment) and `Spree::SellerPayout` (scheduled) are both core and provider-agnostic.## Resolved Decisions@@ -794,7 +794,7 @@ Even before this lands, work touching adjacent areas should:- **Fund ledger → two levels: `Spree::SellerTransfer` (per-order, on-fulfillment) + `Spree::SellerPayout` (per-interval settlement), both generic in core + pluggable `PayoutProvider` (system no-op in core; basic StripeConnect with the monorepo Stripe gateway per the 2026-07-15 amendment, extended by Enterprise with the money operations)** (RESOLVED 2026-06-25). See Decision 9. Transfer credits the seller balance on fulfillment; payout sweeps unsettled transfers into a scheduled bank settlement (transfers `belong_to` their payout — auditable). `seller.balance(currency) = Σ completed transfers − Σ completed payouts` per currency. Splits the legacy gateway-namespaced transfer ledger (which conflated the two and outsourced settlement to Stripe) into core ledger + provider execution along the OSS/Enterprise seam.- **Commission tax → one scalar on the line, in TaxLine's vocabulary** (RESOLVED 2026-08-17). `tax_amount` + `tax_rate` + `taxability_reason` + the seller's `country_code`/`state_code` on `Spree::CommissionLine`, with `Spree::CommissionTax` as the value object the resolver returns. Reusing `Spree::TaxLine` itself was rejected: its rows sum into the order total and are exposed on the buyer-facing `/orders/:id/tax_lines`, so a commission row there would overcharge the shopper and leak settlement data. Same shape, opposite side of the ledger — so the words are shared and the rows are not. See Decision 3.- **Commission VAT base → net item price, VAT added on top of the fee** (RESOLVED 2026-06-25). For EU, commission is computed on the seller's **net (ex-VAT)** item price; the commission `tax_amount` (Decision 3) is then applied **on top of the commission** as a separate B2B service supply — the marketplace fee is a distinct taxable event from the consumer's item sale, so the two VATs never mix. The base toggle stays available for non-EU/edge merchants who genuinely want a gross base, but the EU default is net-base + fee-VAT. Shipped as **`tax_inclusive`** (2026-08-17), matching `Spree::Market#tax_inclusive` rather than the surveyed industry's `include_tax` — the flag says the commission base is tax-inclusive, which is the same adjective the rest of Spree already uses for a price that carries its tax. This makes the marketplace's commission invoice to the seller stand on its own (correct for EU invoicing + remittance).-- **Seller addresses → a stock location + a business identity** (RESOLVED 2026-08-20). `returns_address` is dropped: returns route to a seller-owned `StockLocation` (default provisioned at creation) so received goods restock where the catalog can see them, which also requires `StockLocation` name-uniqueness and the `default` flag to become per-owner rather than per-store. Billing becomes a `Spree::BusinessAddress`, while the parts that are not an address at all become `legal_name` + `registration_number` on the seller and a `Spree::TaxIdentifier` owned by it — reusing the validation/evidence rails the tax plan already built, because EU reverse charge on the commission invoice needs a verified number with retained evidence. No per-seller tax rate (that stays `CommissionRate` + `TaxProvider`); `Spree::BusinessAddress` is a real STI subclass since 2026-08-22 (`spree_addresses` gained `type`), shared with company locations and ready for B2B checkout. See Decision 12.+- **Seller addresses → a stock location + a business identity** (RESOLVED 2026-08-20). `returns_address` is dropped: returns route to a seller-owned `StockLocation` (default provisioned at creation) so received goods restock where the catalog can see them, which also requires `StockLocation` name-uniqueness and the `default` flag to become per-owner rather than per-store. Billing becomes a `Spree::BusinessAddress`, while the parts that are not an address at all become `legal_name` + `registration_number` on the seller and a `Spree::TaxIdentifier` owned by it — reusing the validation/evidence rails the tax plan already built, because EU reverse charge on the commission invoice needs a verified number with retained evidence. No per-seller tax rate (that stays `CommissionRate` + `TaxProvider`) and no `Address` **STI** — `Spree::BusinessAddress` shares `spree_addresses` and the table gains no `type` column (attempted and reverted, decisions.md 2026-08-23). See Decision 12.- **Store-credit/gift-card payout → payment-source-agnostic** (RESOLVED 2026-06-25). The `SellerTransfer` amount (which rolls up into the payout) is `(seller's sale value) − (commission owed)`, **independent of how the customer paid**. Store credit / gift cards are the platform's funding concern, not the seller's — the seller is owed their full cut of the sale regardless. This **drops the legacy store-credit dual-basis** from the amount calculation; that branch existed only to reconcile the old store-credit funding model and does not belong in the payout basis. (The platform still tracks its own store-credit liability separately — that's orthogonal to what the seller receives.)- **Commission precedence → an operator-ordered list** (RESOLVED 2026-06-25 as integer priority; **reshaped 2026-08-17 to `acts_as_list`, shipped**). `CommissionRate` carries `position` (`acts_as_list scope: :store_id, add_new_at: :top`) and resolution walks it top-down, first match wins (Decision 4). The list on screen is the precedence, so reordering is dragging rather than assigning numbers; new rates land at the top so they take effect on creation instead of behind the catch-all. `Spree::Seeds::CommissionRates` puts one disabled marketplace-wide rate at the bottom, which yields the product > category > seller order merchants asked for without hardcoding a ladder. No specificity inference — a rate can name all three dimensions at once, so there is nothing to infer from.- **Commission rate currency → required for fixed, ignored for percentage** (RESOLVED 2026-06-25). A `kind: 'fixed'` rate **must** carry a `currency` (a flat "2" is meaningless without one); a `kind: 'percentage'` rate ignores currency (10% applies in any currency). Enforced by a model validation: `validates :currency, presence: true, if: -> { kind == 'fixed' }`. See the `CommissionRate` model.diff --git a/docs/plans/decisions.md b/docs/plans/decisions.mdindex 5262204ecd..96a0cb2bea 100644--- a/docs/plans/decisions.md+++ b/docs/plans/decisions.md@@ -1,12 +1,20 @@-## 2026-08-22: BusinessAddress is real STI, and it is universal+## 2026-08-23: BusinessAddress stays a table-sharing subclass, not STI-**Context:** `Spree::BusinessAddress` began the day as a table-sharing subclass of `Spree::Address` — no `type` column, the class chosen by whichever association loaded it — serving only the seller's billing address. But company locations carry the same kind of address, and B2B checkout will put one on a cart, where the loading associations (`bill_address`/`ship_address`) are base-typed and cannot choose the class.+**Context:** `Spree::BusinessAddress` overrides three predicates on `Spree::Address` — `require_name?` false, `require_company?` true, `show_company_address_field?` true — and is used by a seller's billing address. It was briefly converted to real STI (a `type` column on `spree_addresses`, an index, a backfill, `CompanyLocation`'s two addresses typed to it), on the argument that the rules should travel with the row so a company address copied onto a cart's base-typed `bill_address` would still validate as a business address. That was reverted the next day.-**Decision:** `spree_addresses` gains a nullable `type` column and the subclass becomes real STI. The rules now travel with the row: an address copied from a company location onto a cart loads back as a `BusinessAddress` and validates as one — company required, no personal name — without checkout knowing anything about it. `CompanyLocation`'s two addresses are typed `BusinessAddress`; the seller's billing address already was. Plain rows keep a NULL type and load as `Spree::Address`. Three consequences inside `Address` itself: `empty?` excludes `type` (a subclass row always carries it), while value comparison and `check`'s dedup keep it — the same postal facts under different validation rules are different addresses, and a business address must never merge into a personal twin another reference depends on. `CompanyLocation` stamps its own company's name onto an address payload lacking one, so the API contract does not start demanding data the branch already knows — deliberately not mirrored on `Seller`, whose billing address is the addressee of a commission invoice and must be stated rather than guessed from a trading name. The migration backfills `type` for rows already referenced by sellers and company locations — without that, a NULL-typed row behind a subclass-typed association reads back as nil, because the STI default scope filters on `type`.+**Decision:** No `type` column on `spree_addresses`. Business-ness is a fact about the **owner** — a seller, a company location, or `company_location_id` on the cart/order — not about the address row, and the owning association already states it.-**Rejected:** keeping table-sharing (the class cannot survive a copy onto a base-typed association, which is exactly the B2B checkout path); a storefront "buying as a company" flag on cart address writes (a Store API design question for when B2B checkout actually lands, not schema work).+Three findings killed the STI argument, all of them checkable in code that already existed:-**Consequences:** callers create the right class — the `becomes` coercion on `Seller#billing_address=` is gone and assigning a plain `Address` record to a typed association raises; the `:business_address` factory is the spec-side answer. Nested attribute writes were already correct: a typed `belongs_to` builds through its reflection, so Hash payloads need nothing. `StockLocation#address` stays a plain `Address` — it is a transient warehouse address for rate quotes and labels, never validated as a business one. No serializer exposes `type`.+1. **Checkout copies attributes, not records.** `Spree::Purchase::Addresses#update_or_create_address` takes a params hash and ends at `Spree::Address.create(attributes)`, hardcoded to the base class. A company location's address entering checkout is reduced to a hash and reborn as a plain `Address`; the `type` never travels. The premise of the STI conversion — that the class survives the copy — was false on the only path that matters.+2. **Keeping `type` significant for dedup breaks address-book reuse.** `find_existing_address` matches on all attributes. With a `type` column, a business address and a personal address with identical postal details never dedupe, so a B2B buyer re-creates a row on every order.+3. **The tax decision never consults the address class.** Per `6.1-channels-catalogs-b2b.md`, exemption hangs off `Company` and `resolved_tax_identifier` walks order → company → customer. The address's Ruby class contributes nothing.++The base `Address` has carried a `company` column and preference-driven `require_company?` / `show_company_address_field?` predicates all along, so the mechanism for "this address belongs to a business" already existed and was already configurable. STI bought two boolean overrides at the cost of a column on one of the most-written tables in Spree, plus knock-on edits to `empty?`, the exclusion-list constants, `json_api_columns`, factories and six specs.++**Rejected:** keeping STI and teaching `update_or_create_address` to preserve the subclass (it fixes the copy path but leaves finding 2, and still buys nothing the owner does not already say).++**Consequences:** `Seller#billing_address=` keeps coercing an assigned plain `Address` with `becomes` — necessary precisely because rows are indistinguishable without a type. `CompanyLocation`'s addresses stay `Spree::Address`; if a mandatory company line is wanted there, it belongs on the owner as a validation, not on the address class. **Constraint:** do not add a `type` column to `spree_addresses` without first checking `update_or_create_address` and `find_existing_address` — the copy path and the dedup path are what decide this, not the model hierarchy.## 2026-08-22: The tax identifier's owner is polymorphicdiff --git a/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rbindex cfd37ad39e..3f3ad0bbeb 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb@@ -36,7 +36,7 @@ RSpec.describe Spree::Api::V3::Admin::CompanyLocationsController, type: :controlendcontext 'with an address already on file' do- let!(:existing) { create(:business_address, address1: 'Alte Str 1', city: 'Berlin') }+ let!(:existing) { create(:address, address1: 'Alte Str 1', city: 'Berlin') }before { location.update!(billing_address: existing) }@@ -75,7 +75,7 @@ RSpec.describe Spree::Api::V3::Admin::CompanyLocationsController, type: :controldescribe 'DELETE #destroy' doit 'removes the branch and the address it owned' do- location.update!(billing_address: create(:business_address))+ location.update!(billing_address: create(:address))expect { delete :destroy, params: { id: location.prefixed_id }, as: :json }.to change(Spree::Address, :count).by(-1)diff --git a/spree/core/app/models/spree/address.rb b/spree/core/app/models/spree/address.rbindex cfdd9c6b1b..2dbe028e78 100644--- a/spree/core/app/models/spree/address.rb+++ b/spree/core/app/models/spree/address.rb@@ -27,11 +27,6 @@ module Spree# those attributes depending of the logic of their applicationsADDRESS_FIELDS = %w(firstname lastname company address1 address2 city state zipcode country phone)EXCLUDED_KEYS_FOR_COMPARISON = %w(id updated_at created_at deleted_at label customer_id metadata)- # Blankness is about what somebody typed, so bookkeeping columns and the- # STI type are ignored. Comparison and dedup deliberately keep `type`: the- # same postal facts under different validation rules are different- # addresses, and a business one must never merge into a personal twin.- EXCLUDED_KEYS_FOR_BLANKNESS = %w(id type created_at updated_at country_id country_code).freezeif defined?(Spree::Security::Addresses)include Spree::Security::Addressesend@@ -239,7 +234,7 @@ module Spree# A country alone doesn't make an address — a new one is pre-filled with the# store's default, so both the code and the association are ignored here.def empty?- attributes.except(*EXCLUDED_KEYS_FOR_BLANKNESS).all? { |_, v| v.nil? }+ attributes.except('id', 'created_at', 'updated_at', 'country_id', 'country_code').all? { |_, v| v.nil? }end# Generates an address hash for payment gateway optionsdiff --git a/spree/core/app/models/spree/business_address.rb b/spree/core/app/models/spree/business_address.rbindex b9bea33e80..bea06e8615 100644--- a/spree/core/app/models/spree/business_address.rb+++ b/spree/core/app/models/spree/business_address.rb@@ -1,11 +1,9 @@module Spree- # The address of a business entity — a seller's billing address, a company- # location's branch. No person to name, and the company is the part that- # cannot be left out.+ # A seller's billing address, as a commission invoice must address it: no+ # person to name, and the company is the part that cannot be left out.#- # STI rather than a class picked by the owning association, so the rules- # travel with the row: copied onto a base-typed association such as a cart's- # bill_address, it still loads and validates as a business address.+ # Shares `spree_addresses` rather than being STI — the table has no `type`+ # column, and the owning association already says which kind this is.class BusinessAddress < Spree::Addressdef require_name?falsediff --git a/spree/core/app/models/spree/company_location.rb b/spree/core/app/models/spree/company_location.rbindex 8d45724eb6..f231f4250b 100644--- a/spree/core/app/models/spree/company_location.rb+++ b/spree/core/app/models/spree/company_location.rb@@ -13,19 +13,17 @@ module Spreeinclude Spree::HasExternalReferencesbelongs_to :company, class_name: 'Spree::Company', inverse_of: :company_locations- belongs_to :billing_address, class_name: 'Spree::BusinessAddress', optional: true, dependent: :destroy- belongs_to :shipping_address, class_name: 'Spree::BusinessAddress', optional: true, dependent: :destroy+ belongs_to :billing_address, class_name: 'Spree::Address', optional: true, dependent: :destroy+ belongs_to :shipping_address, class_name: 'Spree::Address', optional: true, dependent: :destroy# update_only, so editing one field of an existing address changes that# row instead of building a replacement and orphaning the old one.accepts_nested_attributes_for :billing_address, update_only: trueaccepts_nested_attributes_for :shipping_address, update_only: true- ADDRESS_ASSOCIATIONS = %i[billing_address shipping_address].freeze-# The API reads and writes these under the same name, so the writer takes# either a record or the nested hash a client sends.- ADDRESS_ASSOCIATIONS.each do |name|+ %i[billing_address shipping_address].each do |name|define_method(:"#{name}=") do |value|value.is_a?(Hash) || value.is_a?(ActionController::Parameters) ? send(:"#{name}_attributes=", value) : super(value)end@@ -35,33 +33,11 @@ module Spreeinverse_of: :company_locationhas_many :customers, through: :company_contacts, source: :customer- # A business address insists on its company line, but the branch already- # knows whose it is — so a payload without one gets the owning company's- # name stamped in, as a snapshot the invoice can print even if the- # company later renames. Only when an address is actually being written:- # otherwise every unrelated save would load both of them to ask.- before_validation :default_address_company, if: :address_being_written?-validates :name, presence: truedelegate :store, :store_id, to: :companyself.whitelisted_ransackable_attributes = %w[name]self.whitelisted_ransackable_associations = %w[external_references]-- private-- def address_being_written?- ADDRESS_ASSOCIATIONS.any? do |name|- association(name).loaded? || public_send(:"#{name}_id_changed?")- end- end-- def default_address_company- ADDRESS_ASSOCIATIONS.each do |name|- address = public_send(name)- address.company = company&.name if address && address.company.blank?- end- endendenddiff --git a/spree/core/app/models/spree/seller.rb b/spree/core/app/models/spree/seller.rbindex 749d589fac..85b3f2be44 100644--- a/spree/core/app/models/spree/seller.rb+++ b/spree/core/app/models/spree/seller.rb@@ -75,11 +75,19 @@ module Spree# The API reads and writes this under one name, so the writer takes the# attributes a client sends as well as a record. Never an id: an address# carries no store of its own, so binding one by id would reach another- # store's rows.+ # store's rows. A plain Spree::Address is accepted too — the two share+ # `spree_addresses` and differ only in which fields they insist on, so a+ # valid row should not be refused over its Ruby class.def billing_address=(value)- return super unless value.is_a?(Hash) || value.is_a?(ActionController::Parameters)-- self.billing_address_attributes = value+ case value+ when Hash, ActionController::Parameters+ super(Spree::BusinessAddress.new) if billing_address.nil?+ self.billing_address_attributes = value+ when Spree::Address+ super(value.becomes(Spree::BusinessAddress))+ else+ super+ endend# Where this seller keeps stock, and so where their returns land. Releaseddiff --git a/spree/core/db/migrate/20260822000001_add_type_to_spree_addresses.rb b/spree/core/db/migrate/20260822000001_add_type_to_spree_addresses.rbdeleted file mode 100644index 38bcec4a3f..0000000000--- a/spree/core/db/migrate/20260822000001_add_type_to_spree_addresses.rb+++ /dev/null@@ -1,24 +0,0 @@-class AddTypeToSpreeAddresses < ActiveRecord::Migration[8.1]- def up- add_column :spree_addresses, :type, :string- add_index :spree_addresses, :type-- # Rows already referenced as business addresses must carry the type, or- # the subclass-typed associations read them back as nil — STI filters on- # it. Both referencing tables are born in 6.0, so this touches no- # released data and needs no batching.- business_addresses = Class.new(ActiveRecord::Base) { self.table_name = 'spree_addresses' }- sellers = Class.new(ActiveRecord::Base) { self.table_name = 'spree_sellers' }- company_locations = Class.new(ActiveRecord::Base) { self.table_name = 'spree_company_locations' }-- ids = sellers.where.not(billing_address_id: nil).pluck(:billing_address_id) +- company_locations.where.not(billing_address_id: nil).pluck(:billing_address_id) +- company_locations.where.not(shipping_address_id: nil).pluck(:shipping_address_id)-- business_addresses.where(id: ids.uniq).update_all(type: 'Spree::BusinessAddress')- end-- def down- remove_column :spree_addresses, :type- end-enddiff --git a/spree/core/lib/spree/testing_support/factories/address_factory.rb b/spree/core/lib/spree/testing_support/factories/address_factory.rbindex a9dfd71b89..6941078c6f 100644--- a/spree/core/lib/spree/testing_support/factories/address_factory.rb+++ b/spree/core/lib/spree/testing_support/factories/address_factory.rb@@ -39,7 +39,8 @@ FactoryBot.define dozipcode { Spree::TestingSupport::CountryPool.postal_code_for(country&.iso) }# An address addressed to a company rather than a person — a seller's- # billing address, a company location's branch.+ # billing address. Shares the table with its parent, so the only+ # difference is which fields it asks for.factory :business_address, class: Spree::BusinessAddress dofirstname { nil }lastname { nil }diff --git a/spree/core/spec/models/spree/base_spec.rb b/spree/core/spec/models/spree/base_spec.rbindex 859dbd6642..0e747d901b 100644--- a/spree/core/spec/models/spree/base_spec.rb+++ b/spree/core/spec/models/spree/base_spec.rb@@ -54,12 +54,12 @@ describe Spree::Base doexpect(Spree.customer_class.json_api_columns).to include('email')end- it { expect(Spree::Address.json_api_columns).to contain_exactly('address1', 'address2', 'alternative_phone', 'city', 'company', 'country_code', 'created_at', 'deleted_at', 'firstname', 'label', 'lastname', 'phone', 'state_code', 'state_name', 'type', 'updated_at', 'zipcode', 'metadata', 'quick_checkout', 'latitude', 'longitude') }+ it { expect(Spree::Address.json_api_columns).to contain_exactly('address1', 'address2', 'alternative_phone', 'city', 'company', 'country_code', 'created_at', 'deleted_at', 'firstname', 'label', 'lastname', 'phone', 'state_code', 'state_name', 'updated_at', 'zipcode', 'metadata', 'quick_checkout', 'latitude', 'longitude') }it { expect(Spree::Address.json_api_columns).not_to include('country_id') }enddescribe '.json_api_permitted_attributes' do- it { expect(Spree::Address.json_api_permitted_attributes).to contain_exactly('firstname', 'lastname', 'address1', 'address2', 'city', 'zipcode', 'phone', 'country_code', 'state_code', 'state_name', 'alternative_phone', 'company', 'country_id', 'state_id', 'created_at', 'updated_at', 'customer_id', 'deleted_at', 'label', 'metadata', 'quick_checkout', 'latitude', 'longitude', 'type') }+ it { expect(Spree::Address.json_api_permitted_attributes).to contain_exactly('firstname', 'lastname', 'address1', 'address2', 'city', 'zipcode', 'phone', 'country_code', 'state_code', 'state_name', 'alternative_phone', 'company', 'country_id', 'state_id', 'created_at', 'updated_at', 'customer_id', 'deleted_at', 'label', 'metadata', 'quick_checkout', 'latitude', 'longitude') }enddescribe '.additional_permitted_attributes' dodiff --git a/spree/core/spec/models/spree/company_location_spec.rb b/spree/core/spec/models/spree/company_location_spec.rbindex 08bf01dba5..7588aba29b 100644--- a/spree/core/spec/models/spree/company_location_spec.rb+++ b/spree/core/spec/models/spree/company_location_spec.rb@@ -16,7 +16,7 @@ describe Spree::CompanyLocation, type: :model dodescribe 'addresses' doit 'creates them inline from nested attributes' dolocation = create(:company_location, company: company,- billing_address_attributes: build(:address).attributes.except('id', 'type', 'created_at', 'updated_at'))+ billing_address_attributes: build(:address).attributes.except('id', 'created_at', 'updated_at'))expect(location.billing_address).to be_presentend@@ -25,8 +25,8 @@ describe Spree::CompanyLocation, type: :model do# shared is taken away.it 'destroys its own address rows with it' dolocation = create(:company_location, company: company,- billing_address: create(:business_address),- shipping_address: create(:business_address))+ billing_address: create(:address),+ shipping_address: create(:address))expect { location.destroy }.to change(Spree::Address, :count).by(-2)enddiff --git a/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb b/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rbindex 8017dfeb71..e39447a729 100644--- a/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb+++ b/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb@@ -2,7 +2,7 @@ require 'spec_helper'RSpec.describe Spree::Commissions::ResolveTaxRate dolet(:store) { @default_store }- let(:billing_address) { create(:business_address, country_iso: 'DE') }+ let(:billing_address) { create(:address, country_iso: 'DE') }let(:seller) { create(:seller, :approved, store: store, billing_address: billing_address) }let(:order) { create(:order, store: store) }let(:rate) { create(:commission_rate, store: store) }