Files
openfoodnetwork/app/models/spree/stock_movement.rb
cyrillefr 5e18038a68 Fix RedundantPresenceValidationOnBelongs on two files
- 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
2024-05-01 15:43:09 +02:00

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