Class: Shoppe::TaxRate

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AssociatedCountries
Defined in:
app/models/shoppe/tax_rate.rb

Constant Summary collapse

ADDRESS_TYPES =

The order address types which may be used when choosing how to apply the tax rate

['billing', 'delivery']

Instance Method Summary collapse

Methods included from AssociatedCountries

#countries, #country?, included

Instance Method Details

#descriptionString

A description of the tax rate including its name & percentage

Returns:

  • (String)


31
32
33
# File 'app/models/shoppe/tax_rate.rb', line 31

def description
  "#{name} (#{rate}%)"
end

#rate_for(order) ⇒ BigDecimal

The rate for a given order based on the rules on the tax rate

Returns:

  • (BigDecimal)


38
39
40
41
42
43
# File 'app/models/shoppe/tax_rate.rb', line 38

def rate_for(order)
  return rate if countries.empty?
  return rate if address_type == 'billing'  && (order.billing_country.nil?   || country?(order.billing_country))
  return rate if address_type == 'delivery' && (order.delivery_country.nil?  || country?(order.delivery_country))
  BigDecimal(0)
end