From 08055014453d3078619245c91cb794ad471eb93b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 20 Dec 2024 16:20:33 +1100 Subject: [PATCH 1/2] Format spec data with less indent --- spec/system/admin/variant_overrides_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/system/admin/variant_overrides_spec.rb b/spec/system/admin/variant_overrides_spec.rb index a121f1f707..51b07f5e8b 100644 --- a/spec/system/admin/variant_overrides_spec.rb +++ b/spec/system/admin/variant_overrides_spec.rb @@ -254,9 +254,11 @@ RSpec.describe " context "with overrides" do let!(:vo) { - create(:variant_override, :on_demand, variant:, hub:, price: 77.77, - default_stock: 1000, resettable: true, - tag_list: ["tag1", "tag2", "tag3"]) + create( + :variant_override, :on_demand, + variant:, hub:, price: 77.77, default_stock: 1000, resettable: true, + tag_list: ["tag1", "tag2", "tag3"] + ) } let!(:vo_no_auth) { create(:variant_override, variant:, hub: hub2, price: 1, count_on_hand: 2) From a3ec3e74ae1eadf48f2d31ad2bd6c82035f8eaff Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 20 Dec 2024 17:10:44 +1100 Subject: [PATCH 2/2] Hide stock level of on-demand inventory items We changed to tracking stock of on-demand items to be able to place backorders. This is mostly hidden in the app but was still visible on the inventory page. Now we are hiding that here, too. --- app/controllers/admin/variant_overrides_controller.rb | 6 ++++++ app/serializers/api/admin/variant_override_serializer.rb | 6 ++++++ app/serializers/api/admin/variant_simple_serializer.rb | 1 + spec/system/admin/variant_overrides_spec.rb | 3 ++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index 8e8213f61c..d88c25da10 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -71,6 +71,12 @@ module Admin def load_collection collection_hash = Hash[variant_overrides_params.each_with_index.map { |vo, i| [i, vo] }] + + # Reset count_on_hand when switching to producer settings: + collection_hash.each_value do |vo| + vo["count_on_hand"] = nil if vo.fetch("on_demand", :unchanged).nil? + end + @vo_set = Sets::VariantOverrideSet.new(@variant_overrides, collection_attributes: collection_hash) end diff --git a/app/serializers/api/admin/variant_override_serializer.rb b/app/serializers/api/admin/variant_override_serializer.rb index f1663c9b94..f221d6295c 100644 --- a/app/serializers/api/admin/variant_override_serializer.rb +++ b/app/serializers/api/admin/variant_override_serializer.rb @@ -6,6 +6,12 @@ module Api attributes :id, :hub_id, :variant_id, :sku, :price, :count_on_hand, :on_demand, :default_stock, :resettable, :tag_list, :tags, :import_date + def count_on_hand + return if object.on_demand + + object.count_on_hand + end + def tag_list object.tag_list.join(",") end diff --git a/app/serializers/api/admin/variant_simple_serializer.rb b/app/serializers/api/admin/variant_simple_serializer.rb index 3a2944aff0..29425309f5 100644 --- a/app/serializers/api/admin/variant_simple_serializer.rb +++ b/app/serializers/api/admin/variant_simple_serializer.rb @@ -19,6 +19,7 @@ module Api end def on_hand + return if object.on_demand return 0 if object.on_hand.nil? object.on_hand diff --git a/spec/system/admin/variant_overrides_spec.rb b/spec/system/admin/variant_overrides_spec.rb index 51b07f5e8b..2c132f8de2 100644 --- a/spec/system/admin/variant_overrides_spec.rb +++ b/spec/system/admin/variant_overrides_spec.rb @@ -255,7 +255,8 @@ RSpec.describe " context "with overrides" do let!(:vo) { create( - :variant_override, :on_demand, + :variant_override, + on_demand: true, count_on_hand: -5, variant:, hub:, price: 77.77, default_stock: 1000, resettable: true, tag_list: ["tag1", "tag2", "tag3"] )