Sha256: 8b9b575c44d942742f6293dcbaebe86c7e2a7250ef4df7d4a4b9ac86589ad2e1

Contents?: true

Size: 838 Bytes

Versions: 9

Compression:

Stored size: 838 Bytes

Contents

module Spree #:nodoc:
  module TaxCalculator
    def calculate_tax      
      # tax is zero if ship address does not match any existing tax zone
      tax_rates = TaxRate.all.find_all { |rate| rate.zone.include?(ship_address) }
      return 0 if tax_rates.empty?  
      sales_tax_rates = tax_rates.find_all { |rate| rate.tax_type == TaxRate::TaxType::SALES_TAX }
      vat_rates = tax_rates.find_all { |rate| rate.tax_type == TaxRate::TaxType::VAT }

      # note we expect only one of these tax calculations to have a value but its technically possible to model
      # both a sales tax and vat if you wanted to do that for some reason
      sales_tax = Spree::SalesTaxCalculator.calculate_tax(self, sales_tax_rates)
      vat_tax = Spree::VatCalculator.calculate_tax(self, vat_rates)
      
      sales_tax + vat_tax
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree-0.8.4 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.8.5 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.6.0 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.7.0 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.7.1 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.8.0 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.8.1 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.8.2 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb
spree-0.8.3 vendor/extensions/tax_calculator/lib/spree/tax_calculator.rb