Sha256: 9ab3eece6cef1a9c842316f7500ba6ab093d2c49114ce8ece06bdf5d13990ad9

Contents?: true

Size: 594 Bytes

Versions: 14

Compression:

Stored size: 594 Bytes

Contents

module Spree
  class StockMovement < ActiveRecord::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') }

    def readonly?
      !new_record?
    end

    private

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

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
spree_core-2.2.13 app/models/spree/stock_movement.rb
spree_core-2.2.12 app/models/spree/stock_movement.rb
spree_core-2.2.11 app/models/spree/stock_movement.rb
spree_core-2.2.10 app/models/spree/stock_movement.rb
spree_core-2.2.9 app/models/spree/stock_movement.rb
spree_core-2.2.8 app/models/spree/stock_movement.rb
spree_core-2.2.7 app/models/spree/stock_movement.rb
spree_core-2.2.6 app/models/spree/stock_movement.rb
spree_core-2.2.5 app/models/spree/stock_movement.rb
spree_core-2.2.4 app/models/spree/stock_movement.rb
spree_core-2.2.3 app/models/spree/stock_movement.rb
spree_core-2.2.2 app/models/spree/stock_movement.rb
spree_core-2.2.1 app/models/spree/stock_movement.rb
spree_core-2.2.0 app/models/spree/stock_movement.rb