Merge pull request #7699 from guidoDutra/1971-inventory-page-field-validation

Add validation to inventory page fields
This commit is contained in:
Matt-Yorkley
2021-07-01 16:59:20 +02:00
committed by GitHub
2 changed files with 2 additions and 10 deletions

View File

@@ -15,6 +15,8 @@ class VariantOverride < ApplicationRecord
validates :variant, presence: true
# Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero. Need to ensure this can be set by the user.
validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :price, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
default_scope { where(permission_revoked_at: nil) }

View File

@@ -265,16 +265,6 @@ module Spree
li.cap_quantity_at_stock!
expect(li.quantity).to eq 2
end
context "when count on hand is negative" do
before { vo.update(count_on_hand: -3) }
it "caps at zero" do
v.__send__(:stock_item).update_column(:count_on_hand, -2)
li.cap_quantity_at_stock!
expect(li.reload.quantity).to eq 0
end
end
end
end