Sha256: eaaac18f0842904b0bc65f3ad2b9e4d7ee00cef6f5b9f20db7de0a02c2d814b2

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module Workarea
  module Pricing
    module Calculators
      class TaxCalculator
        include Calculator

        def adjust
          adjust_shipped_items_tax
          adjust_not_shipped_items_tax
        end

        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

        def adjust_not_shipped_items_tax
          return unless payment&.address.present?

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

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

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

        # @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.
        #
        # @return [PriceAdjustmentSet]
        #
        def price_adjustments_for(shipping)
          shipped_items_price_adjustments
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-core-3.5.0.beta.1 app/models/workarea/pricing/calculators/tax_calculator.rb