Class: Spree::TaxExemptionReason
- Inherits:
-
Object
- Object
- Spree::TaxExemptionReason
- Defined in:
- app/models/spree/tax_exemption_reason.rb
Overview
Why a business buys without tax — "Resale", "Government", "Charitable
organisation". Certificates point at a reason the way products point at a
tax category: the name is the merchant's own wording, and the code is
what a tax engine reads. Spree's own engine only keeps the code for
reference, while an external one (Avalara's entity use codes) decides the
exemption by it, so changing the code changes what every certificate
holding the reason sends from then on.
Class Method Summary collapse
-
.find_or_create_by_code_or_name!(code:, name:) ⇒ Spree::TaxExemptionReason
Finds the reason already holding the code, else the one holding the name, so seeding a store never collides with a reason the merchant added or renamed.
Instance Method Summary collapse
-
#can_be_deleted? ⇒ Boolean
Mirrors the destroy guard, so the dashboard can hide the delete control rather than offer one the model will refuse.
Methods included from Metadata
#private_metadata, #private_metadata=
Class Method Details
.find_or_create_by_code_or_name!(code:, name:) ⇒ Spree::TaxExemptionReason
Finds the reason already holding the code, else the one holding the name, so seeding a store never collides with a reason the merchant added or renamed. Code first: it is what a tax engine reads, so a match on it is the same reason whatever the merchant called it.
39 40 41 42 43 |
# File 'app/models/spree/tax_exemption_reason.rb', line 39 def self.find_or_create_by_code_or_name!(code:, name:) code = normalize_value_for(:code, code) find_by(code: code) || find_by(name: name) || create!(code: code, name: name) end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
Mirrors the destroy guard, so the dashboard can hide the delete control rather than offer one the model will refuse.
49 50 51 |
# File 'app/models/spree/tax_exemption_reason.rb', line 49 def can_be_deleted? !tax_exemption_certificates.exists? end |