Class: Spree::TaxRate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::TaxRate
- Defined in:
- app/models/spree/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(order) ⇒ Object
Gets the array of TaxRates appropriate for the specified order.
Instance Method Summary collapse
-
#adjust(order) ⇒ Object
Creates necessary tax adjustments for the order.
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
34 35 36 37 38 39 40 41 42 |
# File 'app/models/spree/tax_rate.rb', line 34 def self.default category = TaxCategory.includes(:tax_rates).where(:is_default => true).first return 0 unless category address ||= Address.new(:country_id => Spree::Config[:default_country_id]) rate = category.tax_rates.detect { |rate| rate.zone.include? address }.try(:amount) rate || 0 end |
.match(order) ⇒ Object
Gets the array of TaxRates appropriate for the specified order
24 25 26 27 28 29 |
# File 'app/models/spree/tax_rate.rb', line 24 def self.match(order) return [] unless order.tax_zone all.select do |rate| rate.zone == order.tax_zone || rate.zone.contains?(order.tax_zone) || rate.zone.default_tax end end |
Instance Method Details
#adjust(order) ⇒ Object
Creates necessary tax adjustments for the order.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/spree/tax_rate.rb', line 45 def adjust(order) label = "#{tax_category.name} #{amount * 100}%" if self.included_in_price if Zone.default_tax.contains? order.tax_zone order.line_items.each { |line_item| create_adjustment(label, line_item, line_item) } else amount = -1 * calculator.compute(order) label = I18n.t(:refund) + label order.adjustments.create(:amount => amount, :source => order, :originator => self, :locked => true, :label => label) end else create_adjustment(label, order, order) end end |