Class: Spree::TaxRate

Inherits:
Base
  • Object
show all
Includes:
Discard::Model, AdjustmentSource, CalculatedAdjustments, ParanoiaDeprecations
Defined in:
core/app/models/spree/tax_rate.rb

Instance Method Summary collapse

Methods included from AdjustmentSource

#deals_with_adjustments_for_deleted_source, #remove_adjustments_from_incomplete_orders

Methods included from CalculatedAdjustments

#calculator_type, #calculator_type=

Methods included from ParanoiaDeprecations

#paranoia_delete, #paranoia_destroy

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


108
109
110
111
# File 'core/app/models/spree/tax_rate.rb', line 108

def active?
  (starts_at.nil? || starts_at < Time.current) &&
    (expires_at.nil? || expires_at > Time.current)
end

#adjust(_order_tax_zone, item) ⇒ Object

Creates necessary tax adjustments for the order.



91
92
93
94
95
96
97
98
99
100
101
# File 'core/app/models/spree/tax_rate.rb', line 91

def adjust(_order_tax_zone, item)
  amount = compute_amount(item)

  item.adjustments.create!(
    source: self,
    amount: amount,
    order_id: item.order_id,
    label: adjustment_label(amount),
    included: included_in_price
  )
end

#adjustment_label(amount) ⇒ Object



113
114
115
116
117
118
119
120
# File 'core/app/models/spree/tax_rate.rb', line 113

def adjustment_label(amount)
  I18n.t(
    translation_key(amount),
    scope: "spree.adjustment_labels.tax_rates",
    name: name.presence || tax_categories.map(&:name).join(", "),
    amount: amount_for_adjustment_label
  )
end

#compute_amount(item) ⇒ Object

This method is used by Adjustment#update to recalculate the cost.



104
105
106
# File 'core/app/models/spree/tax_rate.rb', line 104

def compute_amount(item)
  calculator.compute(item)
end

#tax_categoryObject



126
127
128
# File 'core/app/models/spree/tax_rate.rb', line 126

def tax_category
  tax_categories[0]
end

#tax_category=(category) ⇒ Object



122
123
124
# File 'core/app/models/spree/tax_rate.rb', line 122

def tax_category=(category)
  self.tax_categories = [category]
end