Sha256: 27d0138b423bef49a3a725fbb5ed455967f00df5883a6cb366ad8a4016d78c00

Contents?: true

Size: 656 Bytes

Versions: 5

Compression:

Stored size: 656 Bytes

Contents

class TaxRate < ActiveRecord::Base
  belongs_to :zone
  belongs_to :tax_category

  validates :amount, :presence => true, :numericality => true

  calculated_adjustments
  scope :by_zone, lambda { |zone| where("zone_id = ?", zone)}

  # Searches all possible TaxRates and returns the Zone which represents the most appropriate match (if any.)
  # To be considered for a match, the Zone must include the supplied address.  If multiple matches are
  # found, the Zone with the highest rate will be returned.  This method will return +nil+ if no match is found.
  def self.match(address)
    TaxRate.all.select { |rate| rate.zone.include? address }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-0.50.4 app/models/tax_rate.rb
spree_core-0.50.3 app/models/tax_rate.rb
spree_core-0.50.2 app/models/tax_rate.rb
spree_core-0.50.1 app/models/tax_rate.rb
spree_core-0.50.0 app/models/tax_rate.rb