VariantOverride looks up count_on_hand

This commit is contained in:
Rohan Mitchell
2014-12-18 10:21:07 +11:00
parent e6eecd3ae2
commit f5ee9ba2f3
2 changed files with 27 additions and 1 deletions

View File

@@ -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

View File

@@ -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