Class: TaxRate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TaxRate
- Defined in:
- app/models/tax_rate.rb
Class Method Summary collapse
-
.default ⇒ Object
For Vat the default rate is the rate that is configured for the default category It is needed for every price calculation (as all customer facing prices include vat ) The function returns the actual amount, which may be 0 in case of wrong setup, but is never nil.
-
.match(address) ⇒ Object
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.
Class Method Details
.default ⇒ Object
For Vat the default rate is the rate that is configured for the default category It is needed for every price calculation (as all customer facing prices include vat ) The function returns the actual amount, which may be 0 in case of wrong setup, but is never nil
20 21 22 23 24 25 |
# File 'app/models/tax_rate.rb', line 20 def self.default category = TaxCategory.includes(:tax_rates).where(:is_default => true).first return 0 unless category category.effective_amount || 0 end |
.match(address) ⇒ Object
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.
13 14 15 |
# File 'app/models/tax_rate.rb', line 13 def self.match(address) TaxRate.all.select { |rate| rate.zone.include? address } end |