Class: Spree::TaxRate

Inherits:
Base
  • Object
show all
Includes:
Discard::Model, AdjustmentSource, CalculatedAdjustments, ParanoiaDeprecations
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 included from ParanoiaDeprecations

#paranoia_delete, #paranoia_destroy

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

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

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


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

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

#adjust(_order_tax_zone, item) ⇒ Object

Deprecated.

Please use ‘Spree::Tax::OrderAdjuster#adjust!` instead

Creates necessary tax adjustments for the order.



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/spree/tax_rate.rb', line 93

def adjust(_order_tax_zone, item)
  Spree::Deprecation.warn("`Spree::TaxRate#adjust` is deprecated. Please use `Spree::Tax::OrderAdjuster#adjust!` instead.", caller)

  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



117
118
119
120
121
122
123
124
# File 'app/models/spree/tax_rate.rb', line 117

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.



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

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

#tax_categoryObject



130
131
132
# File 'app/models/spree/tax_rate.rb', line 130

def tax_category
  tax_categories[0]
end

#tax_category=(category) ⇒ Object



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

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