Merge pull request #12428 from cyrillefr/RedundantPresenceValidationOnBelongs_part_III

Fix RedundantPresenceValidationOnBelongs on two files
This commit is contained in:
Filipe
2024-05-15 18:21:52 +01:00
committed by GitHub
8 changed files with 75 additions and 15 deletions

View File

@@ -2,15 +2,12 @@
module Spree
class StockItem < ApplicationRecord
self.belongs_to_required_by_default = false
acts_as_paranoid
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
has_many :stock_movements, dependent: :destroy
validates :stock_location, :variant, presence: true
validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] }
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0, unless: :backorderable? }

View File

@@ -2,14 +2,11 @@
module Spree
class StockMovement < ApplicationRecord
self.belongs_to_required_by_default = false
belongs_to :stock_item, class_name: 'Spree::StockItem'
belongs_to :originator, polymorphic: true
belongs_to :originator, polymorphic: true, optional: true
after_create :update_stock_item_quantity
validates :stock_item, presence: true
validates :quantity, presence: true
scope :recent, -> { order('created_at DESC') }