Sha256: 5f2f58ad851cb85f34fe80be2802d00c4ea9a2ef69a5e2e01ad10c011fbc23c1

Contents?: true

Size: 656 Bytes

Versions: 15

Compression:

Stored size: 656 Bytes

Contents

module Spree
  module Stock
    class Quantifier
      attr_reader :stock_items

      def initialize(variant)
        @variant = variant
        @stock_items = Spree::StockItem.joins(:stock_location).where(variant_id: @variant, Spree::StockLocation.table_name => { active: true })
      end

      def total_on_hand
        if @variant.should_track_inventory?
          stock_items.sum(:count_on_hand)
        else
          Float::INFINITY
        end
      end

      def backorderable?
        stock_items.any?(&:backorderable)
      end

      def can_supply?(required)
        total_on_hand >= required || backorderable?
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_core-3.0.10 app/models/spree/stock/quantifier.rb
spree_core-3.0.9 app/models/spree/stock/quantifier.rb
spree_core-3.0.8 app/models/spree/stock/quantifier.rb
spree_core-3.0.7 app/models/spree/stock/quantifier.rb
spree_core-3.0.6.1 app/models/spree/stock/quantifier.rb
spree_core-3.0.6 app/models/spree/stock/quantifier.rb
spree_core-3.0.5 app/models/spree/stock/quantifier.rb
spree_core-3.0.4 app/models/spree/stock/quantifier.rb
spree_core-3.0.3 app/models/spree/stock/quantifier.rb
spree_core-3.0.2 app/models/spree/stock/quantifier.rb
spree_core-3.0.1 app/models/spree/stock/quantifier.rb
spree_core-3.0.0 app/models/spree/stock/quantifier.rb
spree_core-3.0.0.rc4 app/models/spree/stock/quantifier.rb
spree_core-3.0.0.rc3 app/models/spree/stock/quantifier.rb
spree_core-3.0.0.rc1 app/models/spree/stock/quantifier.rb