Class: Calculator::TaxCloudCalculator

Inherits:
DefaultTax
  • Object
show all
Defined in:
app/models/spree/calculator/tax_cloud_calculator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



5
6
7
# File 'app/models/spree/calculator/tax_cloud_calculator.rb', line 5

def self.description
  I18n.t('spree.tax_cloud')
end

Instance Method Details

#compute_order(_order) ⇒ Object

Default tax calculator still needs to support orders for legacy reasons Orders created before Spree 2.1 had tax adjustments applied to the order, as a whole. Orders created with Spree 2.2 and after, have them applied to the line items individually.



12
13
14
# File 'app/models/spree/calculator/tax_cloud_calculator.rb', line 12

def compute_order(_order)
  raise 'Spree::TaxCloud is designed to calculate taxes at the shipment and line-item levels.'
end

#compute_shipment_or_line_item(item) ⇒ Object Also known as: compute_shipment, compute_line_item

When it comes to computing shipments or line items: same same.



17
18
19
20
21
22
23
24
# File 'app/models/spree/calculator/tax_cloud_calculator.rb', line 17

def compute_shipment_or_line_item(item)
  if rate.included_in_price
    raise 'TaxCloud cannot calculate inclusive sales taxes.'
  else
    round_to_two_places(tax_for_item(item))
    # TODO: take discounted_amount into account. This is a problem because TaxCloud API does not take discounts nor does it return percentage rates.
  end
end

#compute_shipping_rate(_shipping_rate) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/spree/calculator/tax_cloud_calculator.rb', line 29

def compute_shipping_rate(_shipping_rate)
  if rate.included_in_price
    raise 'TaxCloud cannot calculate inclusive sales taxes.'
  else
    # Sales tax will be applied to the Shipment itself, rather than to the Shipping Rates.
    # Note that this method is called from ShippingRate.display_price, so if we returned
    # the shipping sales tax here, it would display as part of the display_price of the
    # ShippingRate, which is not consistent with how US sales tax typically works -- i.e.,
    # it is an additional amount applied to a sale at the end, rather than being part of
    # the displayed cost of a good or service.
    0
  end
end