Sha256: 79a3446f1c1e25e2a3d9a126a2ade2071f645e80cadef951a4054358aa70667f

Contents?: true

Size: 1.15 KB

Versions: 61

Compression:

Stored size: 1.15 KB

Contents

require_dependency 'spree/returns_calculator'

module Spree
  module Calculator::Returns
    class DefaultRefundAmount < ReturnsCalculator

      def self.description
        Spree.t(:default_refund_amount)
      end

      def compute(return_item)
        return 0.0.to_d if return_item.exchange_requested?
        weighted_order_adjustment_amount(return_item.inventory_unit) + weighted_line_item_pre_tax_amount(return_item.inventory_unit)
      end

      private

      def weighted_order_adjustment_amount(inventory_unit)
        inventory_unit.order.adjustments.eligible.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit)
      end

      def weighted_line_item_pre_tax_amount(inventory_unit)
        inventory_unit.line_item.pre_tax_amount * percentage_of_line_item(inventory_unit)
      end

      def percentage_of_order_total(inventory_unit)
       return 0.0 if inventory_unit.order.pre_tax_item_amount.zero?
       weighted_line_item_pre_tax_amount(inventory_unit) / inventory_unit.order.pre_tax_item_amount
     end

     def percentage_of_line_item(inventory_unit)
       1 / BigDecimal.new(inventory_unit.line_item.quantity)
     end
   end
 end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spree_core-3.2.9 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.14 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.8 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.13 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.7 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.12 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.6 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.11 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.10 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.5 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.9 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.4 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.8 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.7 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.3 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.2 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.6 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.1.5 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.1 app/models/spree/calculator/returns/default_refund_amount.rb
spree_core-3.2.0 app/models/spree/calculator/returns/default_refund_amount.rb