Class: Spree::TaxLine
- Inherits:
-
Object
- Object
- Spree::TaxLine
- Includes:
- TypedAdjustmentLine
- Defined in:
- app/models/spree/tax_line.rb
Overview
A single tax charge on a line item, fulfillment or fee. Written exclusively
by the tax provider (see Spree::Purchase::Taxation#tax_provider) with replace-all set semantics
per estimate. Snapshot columns (+rate+, label, provider_id) keep rows
self-describing after a TaxRate is deleted or when an external provider
computed them.
Rows on a return, claim or exchange line are post-sale: the tax given back (+credit+), or the tax on an exchange's replacement. They are owned by the order like every other row but never count towards its totals — the order reads only sale rows.
Constant Summary collapse
- BUILT_IN_TAXABILITY_REASONS =
Why this line was taxed the way it was — the machine-readable cause, kept free of any one jurisdiction's invoice vocabulary so reporting and e-invoicing can map it to whatever codes their regime requires.
Configuration, not a frozen constant — a provider modelling a treatment core doesn't know about registers its reason here. The bar for a new value: it distinguishes a treatment that reporting or invoicing has to tell apart, not merely a different amount.
%w[standard_rated reduced_rated zero_rated reverse_charge intra_community_supply export customer_exempt product_exempt not_collecting not_subject_to_tax].freeze
- POST_SALE_KEYS =
%i[return_line_item_id claim_line_item_id exchange_line_item_id].freeze
- ADJUSTABLE_KEYS =
{ 'Spree::LineItem' => :line_item_id, 'Spree::Fulfillment' => :fulfillment_id, 'Spree::Fee' => :fee_id, 'Spree::ReturnLineItem' => :return_line_item_id, 'Spree::ClaimLineItem' => :claim_line_item_id, 'Spree::ExchangeLineItem' => :exchange_line_item_id }.freeze
Class Method Summary collapse
-
.adjustable_key_for(klass) ⇒ Symbol
The foreign key a row uses to point at an item of this class.
Instance Method Summary collapse
- #additional? ⇒ Boolean
- #adjustable ⇒ Spree::LineItem, ...
- #included? ⇒ Boolean
- #post_sale? ⇒ Boolean
Methods included from TypedAdjustmentLine
Class Method Details
.adjustable_key_for(klass) ⇒ Symbol
The foreign key a row uses to point at an item of this class.
94 95 96 |
# File 'app/models/spree/tax_line.rb', line 94 def self.adjustable_key_for(klass) ADJUSTABLE_KEYS.fetch(klass.name) { raise ArgumentError, "#{klass} is not taxable" } end |
Instance Method Details
#additional? ⇒ Boolean
112 113 114 |
# File 'app/models/spree/tax_line.rb', line 112 def additional? !included end |
#adjustable ⇒ Spree::LineItem, ...
100 101 102 |
# File 'app/models/spree/tax_line.rb', line 100 def adjustable line_item || fulfillment || fee || return_line_item || claim_line_item || exchange_line_item end |
#included? ⇒ Boolean
108 109 110 |
# File 'app/models/spree/tax_line.rb', line 108 def included? included end |
#post_sale? ⇒ Boolean
104 105 106 |
# File 'app/models/spree/tax_line.rb', line 104 def post_sale? POST_SALE_KEYS.any? { |key| self[key].present? } end |