Class: Spina::Shop::TaxGroup

Inherits:
ApplicationRecord show all
Defined in:
app/models/spina/shop/tax_group.rb

Instance Method Summary collapse

Instance Method Details

#default_tax_rateObject



13
14
15
# File 'app/models/spina/shop/tax_group.rb', line 13

def default_tax_rate
  tax_rates.default_rate.first_or_initialize
end

#price_modifier_for_order(order) ⇒ Object

The price modifier for calculating exclusive prices is based on the tax rate. If VAT is reverse charged we will use the default rate to calculate the price ex VAT



19
20
21
22
23
# File 'app/models/spina/shop/tax_group.rb', line 19

def price_modifier_for_order(order)
  tax_rate = rate_by_order(order)
  rate = order.vat_reverse_charge? ? default_tax_rate.rate : tax_rate.rate
  (rate + BigDecimal.new(100)) / BigDecimal.new(100)
end

#tax_code_for_order(order) ⇒ Object

Get the tax code based on the order

Priority:

  1. Get code by customer group

  2. Get code by zone

  3. Default Spina config



42
43
44
45
# File 'app/models/spina/shop/tax_group.rb', line 42

def tax_code_for_order(order)
  rate_by_order(order).code || 
    Spina::Shop.config.default_tax_code
end

#tax_rate_for_order(order) ⇒ Object

Get the rate based on the order

Priority:

  1. Get rate by customer group

  2. Get rate by zone

  3. Default Spina config



31
32
33
34
# File 'app/models/spina/shop/tax_group.rb', line 31

def tax_rate_for_order(order)
  rate_by_order(order).rate || 
    Spina::Shop.config.default_tax_rate
end