Sha256: 31fe380066d29b89f162ee4b8d351e917ea38ab7f951324f8e6a5fff1b552117

Contents?: true

Size: 1.42 KB

Versions: 83

Compression:

Stored size: 1.42 KB

Contents

module Spree
  # Tax calculation is broken out at this level to allow easy integration with 3rd party
  # taxation systems.  Those systems are usually geared toward calculating all items at once
  # rather than one at a time.
  #
  # To use an alternative tax calculator do this:
  #    Spree::ReturnAuthorization.reimbursement_tax_calculator = calculator_object
  # where `calculator_object` is an object that responds to "call" and accepts a reimbursement object

  class ReimbursementTaxCalculator
    class << self
      def call(reimbursement)
        reimbursement.return_items.includes(:inventory_unit).each do |return_item|
          set_tax!(return_item)
        end
      end

      private

      def set_tax!(return_item)
        calculated_refund = Spree::ReturnItem.refund_amount_calculator.new.compute(return_item)

        percent_of_tax = if return_item.pre_tax_amount <= 0 || calculated_refund <= 0
                           0
                         else
                           return_item.pre_tax_amount / calculated_refund
                         end

        additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
        included_tax_total   = percent_of_tax * return_item.inventory_unit.included_tax_total

        return_item.update!(additional_tax_total: additional_tax_total,
                                       included_tax_total: included_tax_total)
      end
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.10.0 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.9.0 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.8.3 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.8.2 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.7.3 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.6.6 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.5.5 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.0.9 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.1.15 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.2.7 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.3.3 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.4.1 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.5.4 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.6.5 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.7.2 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.7.1 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.6.4 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.7.0 app/models/spree/reimbursement_tax_calculator.rb
spree_core-4.6.3 app/models/spree/reimbursement_tax_calculator.rb