Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show stock for on-demand inventory items #13064

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/admin/variant_overrides_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def inventory_import_dates

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
Expand Down
6 changes: 6 additions & 0 deletions app/serializers/api/admin/variant_override_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class VariantOverrideSerializer < ActiveModel::Serializer
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
Expand Down
1 change: 1 addition & 0 deletions app/serializers/api/admin/variant_simple_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def name
end

def on_hand
return if object.on_demand
return 0 if object.on_hand.nil?

object.on_hand
Expand Down
9 changes: 6 additions & 3 deletions spec/system/admin/variant_overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@

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: true, count_on_hand: -5,
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)
Expand Down
Loading