Class: Spree::TaxIdentifier
- Inherits:
-
Object
- Object
- Spree::TaxIdentifier
- Defined in:
- app/models/spree/tax_identifier.rb
Overview
The buyer's tax registration — a VAT or business number, typed by kind. Handed to a tax provider through Spree::TaxProvider::Base#estimate, where it is what makes EU B2B reverse charge possible.
Owners, exactly one per row: a customer (the durable profile value), a company (the business a customer buys for), a cart (an override entered during checkout) or an order (the frozen snapshot taken at completion). Orders keep a copy rather than a reference because a registration can be changed or withdrawn later, and an invoice must still show what was true when it was issued.
A seller owns one too, and it faces the other way: the others say how the buyer is taxed, while a seller's registration is what the marketplace's own commission invoice is made out to, and what makes EU reverse charge on that fee possible (docs/plans/6.0-multi-vendor-marketplace.md Decision 12).
The kind column
Which registration this is — an EU VAT number, a UK one, an Australian
business number. Any string is accepted, and nothing here narrows it: the
kinds that exist are the ones somebody has a validator or a provider for,
and core ships one, the format check for eu_vat.
It does have to match the key that validator is registered under in
tax_identifier_validators, because that lookup is by exact string. A kind
nothing is registered for is stored and used as entered — never
format-checked, never sent to a registry — and #validatable? reports as
much. So a misspelled kind fails silently rather than loudly, and a VAT
number filed under vat rather than eu_vat skips the check core does
ship.
The kinds in circulation read as a region or country prefix plus the tax's
name: eu_vat, gb_vat, ch_vat, au_abn. Matching that spares a
validator gem and a storefront from having to agree with each other
directly. It is a habit of the gems that use it, not a rule this model
applies.
Constant Summary collapse
- VALIDATION_STATUSES =
Statuses the platform records rather than the buyer chooses: nil means validation was never attempted, which includes having no validator registered for the kind.
%w[pending verified unverified unavailable unsupported].freeze
- SOURCES =
Which link of the resolution chain produced an order's snapshot.
%w[override company customer].freeze
Instance Method Summary collapse
-
#readonly? ⇒ Boolean
An order-owned row is a completion snapshot: immutable once written, so the tax treatment of a placed order can always be explained.
-
#validatable? ⇒ Boolean
Whether a registry can be asked about a number of this kind here.
- #verified? ⇒ Boolean
Instance Method Details
#readonly? ⇒ Boolean
An order-owned row is a completion snapshot: immutable once written, so the tax treatment of a placed order can always be explained.
94 95 96 |
# File 'app/models/spree/tax_identifier.rb', line 94 def readonly? persisted? && order_owned? end |
#validatable? ⇒ Boolean
Whether a registry can be asked about a number of this kind here. What tells the admin apart the two reasons a row has no verdict: not attempted yet, or nothing here knows how to ask.
A format-only validator does not count. Core registers one for eu_vat,
so a stock install rejects a mistyped VAT number on save and still leaves
the verdict blank — the shape being right is not evidence that the
business is registered, and only a registry can supply that.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/spree/tax_identifier.rb', line 112 def validatable? return false if order_owned? validator = validator_class return false if validator.nil? # A validator predating the predicate, or one not built on Base at all — # the registry takes any class name. Assume it can ask, which is what # every validator did before the predicate existed. return true unless validator.respond_to?(:checks_registry?) validator.checks_registry? end |
#verified? ⇒ Boolean
98 99 100 |
# File 'app/models/spree/tax_identifier.rb', line 98 def verified? validation_status == 'verified' end |