mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
VariantOverride looks up count_on_hand
This commit is contained in:
@@ -9,6 +9,18 @@ class VariantOverride < ActiveRecord::Base
|
||||
}
|
||||
|
||||
def self.price_for(hub, variant)
|
||||
VariantOverride.where(variant_id: variant, hub_id: hub).first.andand.price
|
||||
self.for(hub, variant).andand.price
|
||||
end
|
||||
|
||||
def self.count_on_hand_for(hub, variant)
|
||||
self.for(hub, variant).andand.count_on_hand
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def self.for(hub, variant)
|
||||
VariantOverride.where(variant_id: variant, hub_id: hub).first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -26,4 +26,18 @@ describe VariantOverride do
|
||||
VariantOverride.price_for(hub, variant).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "looking up count on hand" do
|
||||
let(:variant) { create(:variant) }
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
|
||||
it "returns the numeric stock level when present" do
|
||||
VariantOverride.create!(variant: variant, hub: hub, count_on_hand: 12)
|
||||
VariantOverride.count_on_hand_for(hub, variant).should == 12
|
||||
end
|
||||
|
||||
it "returns nil otherwise" do
|
||||
VariantOverride.count_on_hand_for(hub, variant).should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user