diff --git a/app/models/concerns/stock_settings_override_validation.rb b/app/models/concerns/stock_settings_override_validation.rb index 7040cb50e0..b2036991d3 100644 --- a/app/models/concerns/stock_settings_override_validation.rb +++ b/app/models/concerns/stock_settings_override_validation.rb @@ -6,14 +6,14 @@ # `count_on_hand` can either be: nil or a number # # This means that a variant override can be in six different stock states -# but only three of them are valid. +# but only four of them are valid. # # | on_demand | count_on_hand | stock_overridden? | use_producer_stock_settings? | valid? | # |-----------|---------------|-------------------|------------------------------|--------| # | 1 | nil | false | false | true | # | 0 | x | true | false | true | # | nil | nil | false | true | true | -# | 1 | x | ? | ? | false | +# | 1 | x | true | false | true | # | 0 | nil | ? | ? | false | # | nil | x | ? | ? | false | # @@ -27,7 +27,6 @@ module StockSettingsOverrideValidation def require_compatible_on_demand_and_count_on_hand disallow_count_on_hand_if_using_producer_stock_settings - disallow_count_on_hand_if_on_demand require_count_on_hand_if_limited_stock end @@ -39,14 +38,6 @@ module StockSettingsOverrideValidation errors.add(:count_on_hand, error_message) end - def disallow_count_on_hand_if_on_demand - return unless on_demand? && count_on_hand.present? - - error_message = I18n.t("count_on_hand.on_demand_but_count_on_hand_set", - scope: i18n_scope_for_stock_settings_override_validation_error) - errors.add(:count_on_hand, error_message) - end - def require_count_on_hand_if_limited_stock return unless on_demand == false && count_on_hand.blank? diff --git a/config/locales/en.yml b/config/locales/en.yml index f2f0ed92ab..d5743302fa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -127,7 +127,6 @@ en: variant_override: count_on_hand: using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings" - on_demand_but_count_on_hand_set: "must be blank if on demand" limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock" messages: confirmation: "doesn't match %{attribute}" diff --git a/spec/models/spree/variant_stock_spec.rb b/spec/models/spree/variant_stock_spec.rb index b36f989645..4a999fac6c 100644 --- a/spec/models/spree/variant_stock_spec.rb +++ b/spec/models/spree/variant_stock_spec.rb @@ -56,8 +56,6 @@ RSpec.describe Spree::Variant do end it "reduces stock when on demand" do - pending "VariantOverride allowing stock with on_demand" - override.update!(on_demand: true, count_on_hand: 7) expect { diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb index 15c9a1f4bf..38022e206e 100644 --- a/spec/models/variant_override_spec.rb +++ b/spec/models/variant_override_spec.rb @@ -97,11 +97,8 @@ RSpec.describe VariantOverride do context "when count_on_hand is set" do let(:count_on_hand) { 1 } - it "is invalid" do - expect(variant_override).not_to be_valid - error_message = I18n.t("on_demand_but_count_on_hand_set", - scope: [i18n_scope_for_error, "count_on_hand"]) - expect(variant_override.errors[:count_on_hand]).to eq([error_message]) + it "is valid" do + expect(variant_override).to be_valid end end end diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index e916a56a74..49c9069918 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -624,33 +624,6 @@ RSpec.describe "Product Import" do expect(page).not_to have_content "line 3: Sprouts" end - it "handles on_demand and on_hand validations with inventory - With both values set" do - csv_data = <<~CSV - name, distributor, producer, category, on_hand, price, units, on_demand - Beans, Another Enterprise, User Enterprise, Vegetables, 6, 3.20, 500, 1 - Sprouts, Another Enterprise, User Enterprise, Vegetables, 6, 6.50, 500, 1 - Cabbage, Another Enterprise, User Enterprise, Vegetables, 0, 1.50, 500, 1 - CSV - File.write('/tmp/test.csv', csv_data) - - visit main_app.admin_product_import_path - select 'Inventories', from: "settings_import_into" - attach_file 'file', '/tmp/test.csv' - click_button 'Upload' - - proceed_to_validation - - expect(page).to have_selector '.item-count', text: "3" - expect(page).to have_selector '.invalid-count', text: "3" - - find('div.header-description', text: 'Items contain errors').click - expect(page).to have_content "line 2: Beans - Count_on_hand must be blank if on demand" - expect(page).to have_content "line 3: Sprouts - Count_on_hand must be blank if on demand" - expect(page).to have_content "line 4: Cabbage - Count_on_hand must be blank if on demand" - expect(page).to have_content "Imported file contains invalid entries" - expect(page).not_to have_selector 'input[type=submit][value="Save"]' - end - it "imports lines with all allowed units" do csv_data = CSV.generate do |csv| csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",