<commit_before># frozen_string_literal: true

module Spree
  class StockItem < ActiveRecord::Base
    belongs_to :stock_location, class_name: 'Spree::StockLocation'
    belongs_to :variant, class_name: 'Spree::Variant'
    has_many :stock_movements, dependent: :destroy

    validates :stock_location, :variant, presence: true
    # rubocop:disable Rails/UniqueValidationWithoutIndex
    validates :variant_id, uniqueness: { scope: :stock_location_id }
    # rubocop:enable Rails/UniqueValidationWithoutIndex

    attr_accessible :count_on_hand, :variant, :stock_location, :backorderable, :variant_id

    delegate :weight, to: :variant

    def backordered_inventory_units
      Spree::InventoryUnit.backordered_for_stock_item(self)
    end

    delegate :name, to: :variant, prefix: true

    def adjust_count_on_hand(value)
      with_lock do
        self.count_on_hand = count_on_hand + value
        process_backorders if in_stock?

        save!
      end
    end

    def in_stock?
      count_on_hand.positive?
    end

    # Tells whether it's available to be included in a shipment
    def available?
      in_stock? || backorderable?
    end

    private

    def count_on_hand=(value)
      self[:count_on_hand] = value
    end

    def process_backorders
      backordered_inventory_units.each do |unit|
        return unless in_stock?

        unit.fill_backorder
      end
    end
  end
end
<commit_msg>Use break instead of return in StockItem#process_backorders<commit_after># frozen_string_literal: true

module Spree
  class StockItem < ActiveRecord::Base
    belongs_to :stock_location, class_name: 'Spree::StockLocation'
    belongs_to :variant, class_name: 'Spree::Variant'
    has_many :stock_movements, dependent: :destroy

    validates :stock_location, :variant, presence: true
    # rubocop:disable Rails/UniqueValidationWithoutIndex
    validates :variant_id, uniqueness: { scope: :stock_location_id }
    # rubocop:enable Rails/UniqueValidationWithoutIndex

    attr_accessible :count_on_hand, :variant, :stock_location, :backorderable, :variant_id

    delegate :weight, to: :variant

    def backordered_inventory_units
      Spree::InventoryUnit.backordered_for_stock_item(self)
    end

    delegate :name, to: :variant, prefix: true

    def adjust_count_on_hand(value)
      with_lock do
        self.count_on_hand = count_on_hand + value
        process_backorders if in_stock?

        save!
      end
    end

    def in_stock?
      count_on_hand.positive?
    end

    # Tells whether it's available to be included in a shipment
    def available?
      in_stock? || backorderable?
    end

    private

    def count_on_hand=(value)
      self[:count_on_hand] = value
    end

    def process_backorders
      backordered_inventory_units.each do |unit|
        break unless in_stock?

        unit.fill_backorder
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06768483165567511, 'fraction_numerical': 0.0, 'mean_word_length': 3.4, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6862408', 'n_tokens_mistral': 905, 'n_tokens_neox': 866, 'n_words': 216}