mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Merge pull request #7699 from guidoDutra/1971-inventory-page-field-validation
Add validation to inventory page fields
This commit is contained in:
@@ -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) }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user