diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index dcb281ea80..9549d02b2e 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -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 diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb index d592262c97..af6ecb91b7 100644 --- a/spec/models/variant_override_spec.rb +++ b/spec/models/variant_override_spec.rb @@ -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