Sha256: 1c5b804bcf64064124fa14b4693d00ea1dafb7f808f4522334c124f27b984f55

Contents?: true

Size: 876 Bytes

Versions: 1

Compression:

Stored size: 876 Bytes

Contents

module Shoppe
  class TaxRate < ActiveRecord::Base
    
    # Set the table name
    self.table_name = 'shoppe_tax_rates'
    
    # Tax rates are associated with countries
    include Shoppe::AssociatedCountries
    
    # Validations
    validates :name, :presence => true
    validates :rate, :numericality => true
    
    # Relationships
    has_many :products, :dependent => :restrict_with_exception, :class_name => 'Shoppe::Product'
    has_many :delivery_service_prices, :dependent => :restrict_with_exception, :class_name => 'Shoppe::DeliveryServicePrice'
    
    # Scopes
    scope :ordered, -> { order("shoppe_tax_rates.id")}
    
    def description
      "#{name} (#{rate}%)"
    end
    
    def rate_for(order)
      if countries.empty? || order.country.nil? || country?(order.country)
        self.rate
      else
        0.0
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppe-0.0.15 app/models/shoppe/tax_rate.rb