mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
- presence: true is redundant since Rails 5.0 BUT applies with new default config of belongs_to_required_by_default to true. Lots of files with belongs_to_required_by_default = false (backward compatibility). So: deleting this setting implies to adding optional: true - added 'NOT NULL' constraints so model constraints match with contraints on DB tables. - corresponding migration files to match AR Models & DB tables - rake tasks to check corrupt data (ie: NULL/nil in id fields) - updated the todo
21 lines
460 B
Ruby
21 lines
460 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class StockMovement < ApplicationRecord
|
|
belongs_to :stock_item, class_name: 'Spree::StockItem'
|
|
belongs_to :originator, polymorphic: true, optional: true
|
|
|
|
after_create :update_stock_item_quantity
|
|
|
|
validates :quantity, presence: true
|
|
|
|
scope :recent, -> { order('created_at DESC') }
|
|
|
|
private
|
|
|
|
def update_stock_item_quantity
|
|
stock_item.adjust_count_on_hand quantity
|
|
end
|
|
end
|
|
end
|