Class: Spree::TaxRate

Inherits:
Base
  • Object
show all
Includes:
AdjustmentSource, CalculatedAdjustments
Defined in:
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 inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


99
100
101
102
# File 'app/models/spree/tax_rate.rb', line 99

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.



82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/spree/tax_rate.rb', line 82

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



104
105
106
107
108
109
110
111
# File 'app/models/spree/tax_rate.rb', line 104

def adjustment_label(amount)
  Spree.t(
    translation_key(amount),
    scope: "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.



95
96
97
# File 'app/models/spree/tax_rate.rb', line 95

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

#tax_categoryObject



117
118
119
# File 'app/models/spree/tax_rate.rb', line 117

def tax_category
  tax_categories[0]
end

#tax_category=(category) ⇒ Object



113
114
115
# File 'app/models/spree/tax_rate.rb', line 113

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