Sha256: 2387b5ab5dc6e0cba78efa314f5e12d08ba8940c7fbac0d90cfe4888d8f483b5
Contents?: true
Size: 806 Bytes
Versions: 49
Compression:
Stored size: 806 Bytes
Contents
# frozen_string_literal: true module Spree class StockMovement < Spree::Base belongs_to :stock_item, class_name: 'Spree::StockItem', inverse_of: :stock_movements, optional: true belongs_to :originator, polymorphic: true, optional: true has_one :variant, through: :stock_item after_create :update_stock_item_quantity validates :stock_item, presence: true validates :quantity, presence: true scope :recent, -> { order(created_at: :desc) } self.whitelisted_ransackable_associations = %w[variant] 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
49 entries across 49 versions & 1 rubygems