mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-18 04:39:14 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user