mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
26 lines
532 B
Ruby
26 lines
532 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class StockMovement < ApplicationRecord
|
|
belongs_to :stock_item, class_name: 'Spree::StockItem'
|
|
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
|
|
stock_item.adjust_count_on_hand quantity
|
|
end
|
|
end
|
|
end
|