Skip to content

armgit / spree

Public Imported from GitHub
0

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

Hold jurisdiction as a code everywhere this work owns

Łukasz Adamczyk254a9c388c88
diff --git a/docs/plans/6.0-tax-provider.md b/docs/plans/6.0-tax-provider.md
index 6063f4c3ea..09e4b905ed 100644
--- a/docs/plans/6.0-tax-provider.md
+++ b/docs/plans/6.0-tax-provider.md
@@ -378,8 +378,8 @@ class Spree::TaxExemption
attribute :reason_code, :string # resale, government, … (Avalara entityUseCode territory)
attribute :certificate_number, :string # = future TaxExemptionCertificate#certificate_number
- attribute :country_iso, :string # nil = all countries — mirrors the certificate country FK
- attribute :state_code, :string # nil = entire country — mirrors the certificate state FK
+ attribute :country_iso, :string # nil = all countries — same codes the certificate holds
+ attribute :state_code, :string # nil = entire country — same codes the certificate holds
attribute :item_overrides # Array<ItemOverride>; empty = applies to all items
end
@@ -945,8 +945,8 @@ module Spree
included: rate.included_in_price,
provider_id: 'internal',
taxability_reason: reason, # 'standard_rated' / 'zero_rated' / 'customer_exempt'
- country_iso: rate.country&.iso,
- state_code: rate.state&.abbr
+ country_iso: rate.country_iso,
+ state_code: rate.state_code
)
end
end
@@ -1232,8 +1232,8 @@ class CreateSpreeTaxExemptionCertificates < ActiveRecord::Migration[8.1]
def change
create_table :spree_tax_exemption_certificates do |t|
t.references :company, null: false
- t.references :country # nil = every country
- t.references :state # nil = the entire country
+ t.string :country_iso # nil = every country
+ t.string :state_code # nil = the entire country
t.string :certificate_number, null: false
t.string :reason_code, null: false # resale, government, … — becomes the
# provider's entity use code
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 743cb71320..6f2626b889 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -1,4 +1,4 @@
-## 2026-08-12: A tax rate names its jurisdiction by code, not by foreign key
+## 2026-08-12: Jurisdiction is stored as a code, never as a country or state row
Amends 2026-08-06 ("Converted-away columns outlive the release that converts
them"), which had tax rates gaining `country_id`/`state_id`. They gain
@@ -21,6 +21,24 @@ meant in practice, minus the early warning.
Because the columns had not shipped, the original migration was amended rather
than followed by a second one.
+**Extended the same day to everything this work owns**, after a review pass found
+the same shape elsewhere. `Spree::TaxExemptionCertificate` held country and state
+references, and `Spree::PriceRules::ZoneRule` held a `country_ids` preference of
+`Spree::Country` primary keys; both now hold codes (`country_iso`/`state_code`,
+`country_isos`). The certificate case was a live defect rather than a tidy-up:
+an unrecognised ISO resolved to a nil country, and nil claims *every* country
+there, so a mistyped code silently turned one state's certificate into a
+worldwide exemption. A code that matches nothing narrows to nothing.
+
+`Spree::Pricing::Context` gained a `country_iso` reader so a price rule compares
+codes rather than reaching through `context.country`; when Country goes, the
+context is the only place that changes.
+
+**Where a Country object is still correct:** `Purchase::Taxation#tax_country` and
+`Spree::Current.tax_country` return one, and should. Those are lookups in request
+context, not stored jurisdiction, and addresses and markets still speak in
+countries. The rule this entry sets is about what a row *persists*.
+
## 2026-08-12: The label leads, fulfilled follows (amends the Phase 7 fulfill flow)
A warehouse prints the label, sticks it on the box, hands the box over — and
diff --git a/spree/api/app/serializers/spree/api/v3/admin/tax_exemption_certificate_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/tax_exemption_certificate_serializer.rb
index 002a5e8951..e72373d808 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/tax_exemption_certificate_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/tax_exemption_certificate_serializer.rb
@@ -25,13 +25,7 @@ module Spree
# The jurisdiction the certificate holds in, in the same vocabulary the
# tax lines use.
- attribute :country_iso do |certificate|
- certificate.country&.iso
- end
-
- attribute :state_code do |certificate|
- certificate.state&.abbr
- end
+ attributes :country_iso, :state_code
# Whether it counts right now — the status alone can't say, since a
# verified certificate stops counting once its date passes.
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/companies/tax_exemption_certificates_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/companies/tax_exemption_certificates_controller_spec.rb
index 00d7266e16..bf785419e3 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/companies/tax_exemption_certificates_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/companies/tax_exemption_certificates_controller_spec.rb
@@ -23,7 +23,7 @@ RSpec.describe Spree::Api::V3::Admin::Companies::TaxExemptionCertificatesControl
it 'lists the company certificates with whether each counts' do
create(:tax_exemption_certificate, :verified, company: company,
certificate_number: 'DE-1', reason_code: 'resale',
- country: germany)
+ country_iso: germany&.iso)
get :index, params: { company_id: company.prefixed_id }, as: :json
diff --git a/spree/core/app/models/spree/price_rules/zone_rule.rb b/spree/core/app/models/spree/price_rules/zone_rule.rb
index 0e393ee6b2..a0dc9cacf5 100644
--- a/spree/core/app/models/spree/price_rules/zone_rule.rb
+++ b/spree/core/app/models/spree/price_rules/zone_rule.rb
@@ -11,25 +11,33 @@ module Spree
# first-class country rule belongs to docs/plans/6.0-delivery-zones.md,
# which owns the removal of Zone itself.
class ZoneRule < Spree::PriceRule
- # Stored as raw IDs. Accepts prefixed IDs from API callers and decodes
- # them on write, so eligibility compares against raw country_id rows.
- # Countries are global reference data, so unlike MarketRule there is no
- # store scope to confine the existence check to.
- preference :country_ids, :array, default: [],
- parse_on_set: normalize_id_preference(klass: Spree::Country)
+ # Held as ISO codes rather than country rows: Spree::Country is on its way
+ # out, and "DE" is what a merchant means. Comma-separated input is split
+ # and everything upcased, so a rule entered in lowercase still matches.
+ #
+ # Unlike MarketRule, an unknown code is not rejected — there is no country
+ # table to check it against, and an unmatched code narrows the price list
+ # to nothing rather than widening it.
+ preference :country_isos, :array, default: [],
+ parse_on_set: lambda { |values, _owner = nil|
+ Array(values).
+ flat_map { |value| value.to_s.split(',') }.
+ compact_blank.
+ map { |iso| iso.strip.upcase }.
+ uniq
+ }
def applicable?(context)
- return false unless context.country
- return true if preferred_country_ids.empty?
+ return false if context.country_iso.blank?
+ return true if preferred_country_isos.empty?
- # Compare as strings to support both integer and UUID primary keys
- preferred_country_ids.map(&:to_s).include?(context.country.id.to_s)
+ preferred_country_isos.include?(context.country_iso.to_s.upcase)
end
# An empty country list matches every buyer (see #applicable?), so it names
# no geography.
def geographic?
- preferred_country_ids.present?
+ preferred_country_isos.present?
end
def self.description
diff --git a/spree/core/app/models/spree/tax_exemption_certificate.rb b/spree/core/app/models/spree/tax_exemption_certificate.rb
index a9a0a5f084..94335e6236 100644
--- a/spree/core/app/models/spree/tax_exemption_certificate.rb
+++ b/spree/core/app/models/spree/tax_exemption_certificate.rb
@@ -20,8 +20,6 @@ module Spree
has_status :pending, :verified, :expired, :revoked, default: :pending
belongs_to :company, class_name: 'Spree::Company', inverse_of: :tax_exemption_certificates
- belongs_to :country, class_name: 'Spree::Country', optional: true
- belongs_to :state, class_name: 'Spree::State', optional: true
belongs_to :verified_by, class_name: Spree.admin_user_class.to_s, optional: true
# Confidential, so the private service rather than the public one that
@@ -30,8 +28,12 @@ module Spree
validates :certificate_number, :reason_code, presence: true
- before_validation :resolve_state_code
- validate :state_belongs_to_country
+ # Where the certificate holds, as codes: a blank country_iso claims every
+ # country, and a country with no state_code claims all of its states.
+ # Upcased on the way in, and unknown codes are kept as entered — a code
+ # nothing recognises must narrow the certificate to nothing, never widen it
+ # to everywhere, which is what resolving it to a nil country used to do.
+ normalizes :country_iso, :state_code, with: ->(value) { value.presence&.to_s&.upcase }
# Expiry is decided here rather than persisted: the date is the fact, and a
# sweeper writing 'expired' would only restate it. Matches how gift cards
@@ -44,25 +46,14 @@ module Spree
scope :for_address, lambda { |address|
next none if address.nil?
- where(country: [address.country, nil].uniq).where(state: [address.state, nil].uniq)
+ where(country_iso: [address.country_iso.presence, nil].uniq).
+ where(state_code: [address.state_abbr.presence, nil].uniq)
}
self.whitelisted_ransackable_attributes = %w[certificate_number reason_code status expires_at]
delegate :store, :store_id, to: :company
- # The jurisdiction is written in the same vocabulary it is read in, mirroring
- # Spree::TaxRate. State abbreviations repeat across countries, so the state
- # is resolved in a callback once the country is known — a JSON body may name
- # the state first.
- def country_iso=(value)
- self.country = value.present? ? Spree::Country.by_iso(value) : nil
- end
-
- def state_code=(value)
- @state_code_input = value
- end
-
# Accepting a certificate is a decision on record; withdrawing it is
# revocation, not deletion.
def can_be_deleted?
@@ -84,19 +75,5 @@ module Spree
private
- def resolve_state_code
- return unless defined?(@state_code_input)
-
- self.state = @state_code_input.blank? ? nil : Spree::State.where(country_id: country_id).find_by(abbr: @state_code_input)
- remove_instance_variable(:@state_code_input)
- end
-
- # A certificate whose state sits in another country would never match an
- # address — the two columns have to agree.
- def state_belongs_to_country
- return if state.nil? || country.nil? || state.country_id == country_id
-
- errors.add(:state, :invalid)
- end
end
end
diff --git a/spree/core/app/services/spree/tax/resolve_exemptions.rb b/spree/core/app/services/spree/tax/resolve_exemptions.rb
index 3270ab89b6..391bf94cc2 100644
--- a/spree/core/app/services/spree/tax/resolve_exemptions.rb
+++ b/spree/core/app/services/spree/tax/resolve_exemptions.rb
@@ -31,8 +31,8 @@ module Spree
Spree::TaxExemption.new(
reason_code: certificate.reason_code,
certificate_number: certificate.certificate_number,
- country_iso: certificate.country&.iso,
- state_code: certificate.state&.abbr
+ country_iso: certificate.country_iso,
+ state_code: certificate.state_code
)
end
)
diff --git a/spree/core/db/migrate/20260807000003_create_spree_tax_exemption_certificates.rb b/spree/core/db/migrate/20260807000003_create_spree_tax_exemption_certificates.rb
index a76c18013d..cdc4562d7c 100644
--- a/spree/core/db/migrate/20260807000003_create_spree_tax_exemption_certificates.rb
+++ b/spree/core/db/migrate/20260807000003_create_spree_tax_exemption_certificates.rb
@@ -2,8 +2,10 @@ class CreateSpreeTaxExemptionCertificates < ActiveRecord::Migration[8.1]
def change
create_table :spree_tax_exemption_certificates do |t|
t.references :company, null: false
- t.references :country # nil = every country
- t.references :state # nil = the entire country
+ # Codes, not references: Country and State are being dropped, and a blank
+ # code is what "everywhere" means here. Same shape as spree_tax_rates.
+ t.string :country_iso # nil = every country
+ t.string :state_code # nil = the entire country
t.string :certificate_number, null: false
t.string :reason_code, null: false # resale, government, … — becomes the
# provider's entity use code
@@ -24,5 +26,6 @@ class CreateSpreeTaxExemptionCertificates < ActiveRecord::Migration[8.1]
end
add_index :spree_tax_exemption_certificates, [:company_id, :status]
+ add_index :spree_tax_exemption_certificates, [:country_iso, :state_code]
end
end
diff --git a/spree/core/lib/spree/core/pricing/context.rb b/spree/core/lib/spree/core/pricing/context.rb
index 9b2da2aa88..fcb97f4349 100644
--- a/spree/core/lib/spree/core/pricing/context.rb
+++ b/spree/core/lib/spree/core/pricing/context.rb
@@ -27,6 +27,14 @@ module Spree
@order = order
end
+ # The destination as a code. Rules compare against this rather than the
+ # country row, so eligibility keeps working once Spree::Country is gone.
+ #
+ # @return [String, nil]
+ def country_iso
+ country&.iso
+ end
+
# Returns a new context from a variant and currency
# @param variant [Spree::Variant]
# @param currency [String]
diff --git a/spree/core/lib/spree/testing_support/factories/price_rule_factory.rb b/spree/core/lib/spree/testing_support/factories/price_rule_factory.rb
index 8e53ae1857..b4700c779f 100644
--- a/spree/core/lib/spree/testing_support/factories/price_rule_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/price_rule_factory.rb
@@ -4,11 +4,11 @@ FactoryBot.define do
factory :zone_price_rule, class: Spree::PriceRules::ZoneRule do
after(:build) do |rule, evaluator|
- rule.preferred_country_ids = evaluator.country_ids if evaluator.respond_to?(:country_ids)
+ rule.preferred_country_isos = evaluator.country_isos if evaluator.respond_to?(:country_isos)
end
transient do
- country_ids { [] }
+ country_isos { [] }
end
end
diff --git a/spree/core/lib/tasks/tax_zones_migration.rake b/spree/core/lib/tasks/tax_zones_migration.rake
index c066ff0384..b12d8aa02b 100644
--- a/spree/core/lib/tasks/tax_zones_migration.rake
+++ b/spree/core/lib/tasks/tax_zones_migration.rake
@@ -61,19 +61,21 @@ namespace :spree do
# country, so restate each one as the countries its zones contained. A
# zone that named individual states becomes those states' countries, which
# widens the rule — reported below so the merchant can narrow it by hand.
- # Both id lists go through their model, so a member pointing at a deleted
- # country or state drops out instead of being written back as a live
- # reference.
+ # Both lists resolve through their model on the way out, so a member
+ # pointing at a deleted country or state drops out instead of being written
+ # back as a code nothing issued.
countries_for = lambda do |zone_ids|
members = Spree::ZoneMember.where(zone_id: zone_ids)
- country_ids = Spree::Country.where(
+ country_isos = Spree::Country.where(
id: members.where(zoneable_type: 'Spree::Country').pluck(:zoneable_id)
- ).pluck(:id)
- state_country_ids = Spree::State.where(
- id: members.where(zoneable_type: 'Spree::State').pluck(:zoneable_id)
- ).pluck(:country_id)
+ ).pluck(:iso)
+ state_country_isos = Spree::Country.where(
+ id: Spree::State.where(
+ id: members.where(zoneable_type: 'Spree::State').pluck(:zoneable_id)
+ ).select(:country_id)
+ ).pluck(:iso)
- [(country_ids + state_country_ids).uniq.map(&:to_s), state_country_ids.any?]
+ [(country_isos + state_country_isos).compact.uniq.map(&:upcase), state_country_isos.any?]
end
rules_converted = 0
@@ -83,11 +85,11 @@ namespace :spree do
Spree::PriceRules::ZoneRule.find_each do |rule|
stored = rule.preferences.with_indifferent_access
zone_ids = Array(stored[:zone_ids]).reject(&:blank?)
- next if stored[:country_ids].present? || zone_ids.empty?
+ next if stored[:country_isos].present? || zone_ids.empty?
- country_ids, from_states = countries_for.call(zone_ids)
+ country_isos, from_states = countries_for.call(zone_ids)
rule.update_columns(
- preferences: stored.except(:zone_ids).merge(country_ids: country_ids).to_h.symbolize_keys,
+ preferences: stored.except(:zone_ids).merge(country_isos: country_isos).to_h.symbolize_keys,
updated_at: Time.current
)
rules_converted += 1
@@ -95,7 +97,7 @@ namespace :spree do
# A zone that was deleted, or had no members, leaves nothing to restrict
# by, so the rule stops narrowing its price list at all. Called out
# because it is the one outcome here a merchant would not predict.
- rules_unrestricted += 1 if country_ids.empty?
+ rules_unrestricted += 1 if country_isos.empty?
end
puts " Restated #{rules_converted} zone price rule(s) as countries " \
diff --git a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
index c5e0c0ff2b..753f389fe0 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
@@ -286,7 +286,7 @@ describe '6.0 data migration tasks' do
run_task('spree:migrate_tax_zones')
- expect(rule.reload.preferred_country_ids).to contain_exactly(germany.id.to_s, france.id.to_s)
+ expect(rule.reload.preferred_country_isos).to contain_exactly(germany.iso, france.iso)
end
# A state-level zone can only be expressed as its states' countries,
@@ -297,26 +297,26 @@ describe '6.0 data migration tasks' do
run_task('spree:migrate_tax_zones')
- expect(rule.reload.preferred_country_ids).to eq([germany.id.to_s])
+ expect(rule.reload.preferred_country_isos).to eq([germany.iso])
end
it 'is idempotent over a legacy row' do
rule = legacy_rule(zone_with(germany))
run_task('spree:migrate_tax_zones')
- converted = rule.reload.preferred_country_ids
+ converted = rule.reload.preferred_country_isos
run_task('spree:migrate_tax_zones')
- expect(rule.reload.preferred_country_ids).to eq(converted)
+ expect(rule.reload.preferred_country_isos).to eq(converted)
expect(rule.reload.preferences).not_to have_key(:zone_ids)
end
it 'leaves a rule the merchant already set countries on alone' do
- rule = create(:zone_price_rule, price_list: price_list, country_ids: [france.id])
+ rule = create(:zone_price_rule, price_list: price_list, country_isos: [france.iso])
run_task('spree:migrate_tax_zones')
- expect(rule.reload.preferred_country_ids).to eq([france.id.to_s])
+ expect(rule.reload.preferred_country_isos).to eq([france.iso])
end
# A zone that was deleted and one that never had members both leave no
@@ -327,7 +327,7 @@ describe '6.0 data migration tasks' do
run_task('spree:migrate_tax_zones')
- expect(rule.reload.preferred_country_ids).to be_empty
+ expect(rule.reload.preferred_country_isos).to be_empty
expect(rule.preferences).not_to have_key(:zone_ids)
end
end
diff --git a/spree/core/spec/models/spree/price_rules/zone_rule_spec.rb b/spree/core/spec/models/spree/price_rules/zone_rule_spec.rb
index 1a96e95c62..c01b9ca08b 100644
--- a/spree/core/spec/models/spree/price_rules/zone_rule_spec.rb
+++ b/spree/core/spec/models/spree/price_rules/zone_rule_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Spree::PriceRules::ZoneRule, type: :model do
let(:price_list) { create(:price_list) }
let(:rule) { create(:zone_price_rule, price_list: price_list) }
- let(:country) { create(:country) }
+ let(:country) { create(:country, iso: 'DE', name: 'Germany') }
let(:variant) { create(:variant) }
def context_for(country_record = nil)
@@ -11,23 +11,23 @@ describe Spree::PriceRules::ZoneRule, type: :model do
end
describe '#applicable?' do
- context 'when country_ids preference is empty' do
- before { rule.preferred_country_ids = [] }
+ context 'when no country is named' do
+ before { rule.preferred_country_isos = [] }
it 'returns true for any country' do
expect(rule.applicable?(context_for(country))).to be true
end
end
- context 'when country_ids preference is set' do
- before { rule.preferred_country_ids = [country.id] }
+ context 'when a country is named' do
+ before { rule.preferred_country_isos = [country.iso] }
it 'returns true when the context country matches' do
expect(rule.applicable?(context_for(country))).to be true
end
it 'returns false when the context country does not match' do
- expect(rule.applicable?(context_for(create(:country)))).to be false
+ expect(rule.applicable?(context_for(create(:country, iso: 'FR', name: 'France')))).to be false
end
# A context built without a country falls back to the store's, so nil only
@@ -42,23 +42,33 @@ describe Spree::PriceRules::ZoneRule, type: :model do
end
end
- # UUID primary keys mean an id may arrive as either type.
- context 'when country_ids preference contains strings' do
- before { rule.preferred_country_ids = [country.id.to_s] }
+ # Codes arrive from merchants, so case is not guaranteed either way.
+ context 'when the code was entered in lowercase' do
+ before { rule.preferred_country_isos = ['de'] }
it 'returns true when the context country matches' do
expect(rule.applicable?(context_for(country))).to be true
end
it 'returns false when the context country does not match' do
- expect(rule.applicable?(context_for(create(:country)))).to be false
+ expect(rule.applicable?(context_for(create(:country, iso: 'FR', name: 'France')))).to be false
+ end
+ end
+
+ # There is no country table to check a code against, so an unknown one has
+ # to narrow the price list to nothing rather than widen it to everywhere.
+ context 'when the code is one nothing issued' do
+ before { rule.preferred_country_isos = ['ZZ'] }
+
+ it 'returns false for every country' do
+ expect(rule.applicable?(context_for(country))).to be false
end
end
end
describe '#geographic?' do
it 'is true once countries are named' do
rule = described_class.new(price_list: price_list)
- rule.preferred_country_ids = [country.id]
+ rule.preferred_country_isos = [country.iso]
expect(rule.geographic?).to be(true)
end
diff --git a/spree/core/spec/models/spree/tax_exemption_certificate_spec.rb b/spree/core/spec/models/spree/tax_exemption_certificate_spec.rb
index 4af67eb5d9..7ba892b7d2 100644
--- a/spree/core/spec/models/spree/tax_exemption_certificate_spec.rb
+++ b/spree/core/spec/models/spree/tax_exemption_certificate_spec.rb
@@ -56,29 +56,46 @@ describe Spree::TaxExemptionCertificate, type: :model do
end
it 'matches one naming the country' do
- certificate = create(:tax_exemption_certificate, company: company, country: germany)
+ certificate = create(:tax_exemption_certificate, company: company, country_iso: germany&.iso)
expect(described_class.for_address(address)).to include(certificate)
end
it 'matches one naming the exact state' do
- certificate = create(:tax_exemption_certificate, company: company, country: germany, state: berlin)
+ certificate = create(:tax_exemption_certificate, company: company, country_iso: germany&.iso, state_code: berlin&.abbr)
expect(described_class.for_address(address)).to include(certificate)
end
it 'excludes one naming another state of the same country' do
other = create(:state, country: germany, abbr: 'HH', name: 'Hamburg')
- certificate = create(:tax_exemption_certificate, company: company, country: germany, state: other)
+ certificate = create(:tax_exemption_certificate, company: company, country_iso: germany&.iso, state_code: other&.abbr)
expect(described_class.for_address(address)).not_to include(certificate)
end
it 'excludes one naming another country' do
- certificate = create(:tax_exemption_certificate, company: company, country: create(:country, iso: 'FR'))
+ certificate = create(:tax_exemption_certificate, company: company, country_iso: create(:country, iso: 'FR')&.iso)
expect(described_class.for_address(address)).not_to include(certificate)
end
+
+ # The reason the jurisdiction is a code rather than a country row: an
+ # unrecognised code used to resolve to nil, and nil claims every country
+ # here — so a typo turned one state's certificate into a worldwide
+ # exemption. It must narrow to nothing instead.
+ it 'never matches when the country code is one nothing recognises' do
+ certificate = create(:tax_exemption_certificate, company: company, country_iso: 'ZZ')
+
+ expect(described_class.for_address(address)).not_to include(certificate)
+ end
+
+ it 'stores the jurisdiction upcased however it was entered' do
+ certificate = create(:tax_exemption_certificate, company: company, country_iso: 'de', state_code: 'be')
+
+ expect(certificate.country_iso).to eq('DE')
+ expect(certificate.state_code).to eq('BE')
+ end
end
describe '#can_be_deleted?' do
diff --git a/spree/core/spec/models/spree/tax_provider/internal_spec.rb b/spree/core/spec/models/spree/tax_provider/internal_spec.rb
index da66e09f36..800da12d8c 100644
--- a/spree/core/spec/models/spree/tax_provider/internal_spec.rb
+++ b/spree/core/spec/models/spree/tax_provider/internal_spec.rb
@@ -168,7 +168,7 @@ describe Spree::TaxProvider::Internal, type: :model do
it 'exempts the sale instead of taxing it' do
create(:tax_exemption_certificate, :verified, company: company,
reason_code: 'resale', certificate_number: 'CERT-9',
- country: country)
+ country_iso: country&.iso)
provider.estimate(order, exemptions: resolved_exemptions)
@@ -179,7 +179,7 @@ describe Spree::TaxProvider::Internal, type: :model do
end
it 'taxes normally while the certificate is still awaiting verification' do
- create(:tax_exemption_certificate, company: company, country: country)
+ create(:tax_exemption_certificate, company: company, country_iso: country&.iso)
provider.estimate(order, exemptions: resolved_exemptions)
diff --git a/spree/core/spec/services/spree/tax/resolve_exemptions_spec.rb b/spree/core/spec/services/spree/tax/resolve_exemptions_spec.rb
index dadbbb2206..fc212a21e0 100644
--- a/spree/core/spec/services/spree/tax/resolve_exemptions_spec.rb
+++ b/spree/core/spec/services/spree/tax/resolve_exemptions_spec.rb
@@ -26,7 +26,7 @@ describe Spree::Tax::ResolveExemptions do
it 'turns an active certificate into a claim' do
create(:tax_exemption_certificate, :verified, company: company,
reason_code: 'resale', certificate_number: 'DE-RESALE-1',
- country: germany, state: berlin)
+ country_iso: germany&.iso, state_code: berlin&.abbr)
exemption = described_class.call(order: order.reload).value.sole
@@ -57,7 +57,7 @@ describe Spree::Tax::ResolveExemptions do
end
it 'ignores one held for another jurisdiction' do
- create(:tax_exemption_certificate, :verified, company: company, country: create(:country, iso: 'FR'))
+ create(:tax_exemption_certificate, :verified, company: company, country_iso: create(:country, iso: 'FR')&.iso)
expect(described_class.call(order: order.reload).value).to eq([])
end