Sha256: 604f848cb5684e41d229f351b16ab2fbf3e96f46ec8dccc4ae6d5ce3f71f8943

Contents?: true

Size: 647 Bytes

Versions: 15

Compression:

Stored size: 647 Bytes

Contents

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 self.stock_item.should_track_inventory?
      stock_item.adjust_count_on_hand quantity
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
solidus_core-1.2.3 app/models/spree/stock_movement.rb
solidus_core-1.1.4 app/models/spree/stock_movement.rb
solidus_core-1.2.2 app/models/spree/stock_movement.rb
solidus_core-1.2.1 app/models/spree/stock_movement.rb
solidus_core-1.1.3 app/models/spree/stock_movement.rb
solidus_core-1.2.0 app/models/spree/stock_movement.rb
solidus_core-1.2.0.rc2 app/models/spree/stock_movement.rb
solidus_core-1.1.2 app/models/spree/stock_movement.rb
solidus_core-1.2.0.rc1 app/models/spree/stock_movement.rb
solidus_core-1.2.0.beta1 app/models/spree/stock_movement.rb
solidus_core-1.1.1 app/models/spree/stock_movement.rb
solidus_core-1.1.0 app/models/spree/stock_movement.rb
solidus_core-1.1.0.pre2 app/models/spree/stock_movement.rb
solidus_core-1.1.0.pre1 app/models/spree/stock_movement.rb
solidus_core-1.1.0.beta1 app/models/spree/stock_movement.rb