Class: Workarea::Pricing::Calculators::TaxCalculator

Inherits:
Object
  • Object
show all
Includes:
Workarea::Pricing::Calculator
Defined in:
app/models/workarea/pricing/calculators/tax_calculator.rb

Instance Method Summary collapse

Methods included from Workarea::Pricing::Calculator

#initialize

Instance Method Details

#adjustObject



7
8
9
10
# File 'app/models/workarea/pricing/calculators/tax_calculator.rb', line 7

def adjust
  adjust_shipped_items_tax
  adjust_not_shipped_items_tax
end

#adjust_not_shipped_items_taxObject



21
22
23
24
25
26
27
28
# File 'app/models/workarea/pricing/calculators/tax_calculator.rb', line 21

def adjust_not_shipped_items_tax
  return unless payment&.address.present?

  ItemTaxApplier.new(
    payment.address,
    not_shipped_items_price_adjustments
  ).apply
end

#adjust_shipped_items_taxObject



12
13
14
15
16
17
18
19
# File 'app/models/workarea/pricing/calculators/tax_calculator.rb', line 12

def adjust_shipped_items_tax
  shippings.each do |tmp_shipping|
    next unless tmp_shipping.address.present?

    adjustments_to_tax = price_adjustments_for(tmp_shipping)
    TaxApplier.new(tmp_shipping, adjustments_to_tax).apply
  end
end

#not_shipped_items_price_adjustmentsObject



36
37
38
39
40
# File 'app/models/workarea/pricing/calculators/tax_calculator.rb', line 36

def not_shipped_items_price_adjustments
  PriceAdjustmentSet.new(
    order.items.reject(&:shipping?).flat_map(&:price_adjustments)
  )
end

#price_adjustments_for(shipping) ⇒ PriceAdjustmentSet

Deprecated.

As of v3.5, this class supports applying tax directly to

items when they do not require shipping. As a result tax calculation is split on this distinction and this method is no longer sufficient. Instead modify the appropriate method to change the set of price adjustments to consider for tax calculation.

Returns:



50
51
52
# File 'app/models/workarea/pricing/calculators/tax_calculator.rb', line 50

def price_adjustments_for(shipping)
  shipped_items_price_adjustments
end

#shipped_items_price_adjustmentsObject



30
31
32
33
34
# File 'app/models/workarea/pricing/calculators/tax_calculator.rb', line 30

def shipped_items_price_adjustments
  PriceAdjustmentSet.new(
    order.items.select(&:shipping?).flat_map(&:price_adjustments)
  )
end