From 36e6d96e17f148b1e5855f547da444ea12d20356 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 20 Mar 2024 16:39:35 +1100 Subject: [PATCH] Remove validation of positive stock when on demand We weren't allowing negative stock to stop any bug from accidentally drawing too much stock. But now we want to implement a backordering logic that depends on negative stock levels to know how much is needed to replenish stock levels. --- app/models/variant_override.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index ea5dca61b2..447ea53b6f 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -15,7 +15,9 @@ class VariantOverride < ApplicationRecord # 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 + validates :count_on_hand, numericality: { + greater_than_or_equal_to: 0, unless: :on_demand? + }, allow_nil: true default_scope { where(permission_revoked_at: nil) }