-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
shipping_rate_tax.rb
39 lines (32 loc) · 973 Bytes
/
shipping_rate_tax.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
module Spree
# Used to persist shipping rate tax estimations.
# @attr [Spree::ShippingRate] shipping_rate The shipping rate to be taxed
# @attr [Spree::TaxRate] tax_rate The tax rate used to calculate the tax amount
# @since 1.3.0
# @see Spree::Tax::ShippingRateTaxer
class ShippingRateTax < ActiveRecord::Base
belongs_to :shipping_rate, class_name: "Spree::ShippingRate"
belongs_to :tax_rate, class_name: "Spree::TaxRate"
extend DisplayMoney
money_methods :absolute_amount
delegate :currency, to: :shipping_rate, allow_nil: true
def label
I18n.t translation_key,
scope: 'spree.shipping_rate_tax.label',
amount: display_absolute_amount,
tax_rate_name: tax_rate.name
end
def absolute_amount
amount.abs
end
private
def translation_key
if tax_rate.included_in_price?
:vat
else
:sales_tax
end
end
end
end