Sha256: 41556b1c67b1087a5f80659ab21c4603e7c5db6df5ff754d59df22aaef715313

Contents?: true

Size: 671 Bytes

Versions: 42

Compression:

Stored size: 671 Bytes

Contents

# frozen_string_literal: true

module Spree
  class StockMovement < Spree::Base
    belongs_to :stock_item, class_name: 'Spree::StockItem', inverse_of: :stock_movements
    belongs_to :originator, polymorphic: true

    after_create :update_stock_item_quantity

    validates :stock_item, presence: true
    validates :quantity, presence: true

    scope :recent, -> { order(created_at: :desc) }

    self.whitelisted_ransackable_attributes = ['quantity']

    def readonly?
      !new_record?
    end

    private

    def update_stock_item_quantity
      return unless stock_item.should_track_inventory?
      stock_item.adjust_count_on_hand quantity
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
solidus_core-2.9.6 app/models/spree/stock_movement.rb
solidus_core-2.8.6 app/models/spree/stock_movement.rb
solidus_core-2.9.5 app/models/spree/stock_movement.rb
solidus_core-2.9.4 app/models/spree/stock_movement.rb
solidus_core-2.6.6 app/models/spree/stock_movement.rb
solidus_core-2.7.4 app/models/spree/stock_movement.rb
solidus_core-2.8.5 app/models/spree/stock_movement.rb
solidus_core-2.9.3 app/models/spree/stock_movement.rb
solidus_core-2.9.2 app/models/spree/stock_movement.rb
solidus_core-2.7.3 app/models/spree/stock_movement.rb
solidus_core-2.6.5 app/models/spree/stock_movement.rb
solidus_core-2.9.1 app/models/spree/stock_movement.rb
solidus_core-2.9.0 app/models/spree/stock_movement.rb
solidus_core-2.9.0.rc.1 app/models/spree/stock_movement.rb
solidus_core-2.8.4 app/models/spree/stock_movement.rb
solidus_core-2.8.3 app/models/spree/stock_movement.rb
solidus_core-2.7.2 app/models/spree/stock_movement.rb
solidus_core-2.6.4 app/models/spree/stock_movement.rb
solidus_core-2.8.2 app/models/spree/stock_movement.rb
solidus_core-2.8.1 app/models/spree/stock_movement.rb