Class: Spina::Shop::TaxGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Shop::TaxGroup
- Defined in:
- app/models/spina/shop/tax_group.rb
Instance Method Summary collapse
- #default_tax_rate ⇒ Object
-
#price_modifier_for_order(order) ⇒ Object
The price modifier for calculating exclusive prices is based on the tax rate.
-
#tax_code_for_order(order) ⇒ Object
Get the tax code based on the order.
-
#tax_rate_for_order(order) ⇒ Object
Get the rate based on the order.
Instance Method Details
#default_tax_rate ⇒ Object
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:
-
Get code by customer group
-
Get code by zone
-
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:
-
Get rate by customer group
-
Get rate by zone
-
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 |