Class: Spree::TaxRate
- Includes:
- AdjustmentSource, CalculatedAdjustments
- Defined in:
- app/models/spree/tax_rate.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#adjust(_order_tax_zone, item) ⇒ Object
Creates necessary tax adjustments for the order.
- #adjustment_label(amount) ⇒ Object
-
#compute_amount(item) ⇒ Object
This method is used by Adjustment#update to recalculate the cost.
- #tax_category ⇒ Object
- #tax_category=(category) ⇒ Object
Methods included from AdjustmentSource
#deals_with_adjustments_for_deleted_source
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
101 102 103 104 |
# File 'app/models/spree/tax_rate.rb', line 101 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 93 94 |
# File 'app/models/spree/tax_rate.rb', line 82 def adjust(_order_tax_zone, item) amount = compute_amount(item) included = included_in_price && amount > 0 item.adjustments.create!( source: self, amount: amount, order_id: item.order_id, label: adjustment_label(amount), included: included ) end |
#adjustment_label(amount) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'app/models/spree/tax_rate.rb', line 106 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.
97 98 99 |
# File 'app/models/spree/tax_rate.rb', line 97 def compute_amount(item) calculator.compute(item) end |
#tax_category ⇒ Object
119 120 121 |
# File 'app/models/spree/tax_rate.rb', line 119 def tax_category tax_categories[0] end |
#tax_category=(category) ⇒ Object
115 116 117 |
# File 'app/models/spree/tax_rate.rb', line 115 def tax_category=(category) self.tax_categories = [category] end |