Enterprise.active_distributors doesn't show distributors of out of stock products

This commit is contained in:
Rohan Mitchell
2013-03-08 16:48:35 +11:00
parent 13abf9ada7
commit 2a890f80f4
2 changed files with 6 additions and 2 deletions

View File

@@ -35,7 +35,7 @@ class Enterprise < ActiveRecord::Base
scope :active_distributors, lambda {
with_distributed_products_outer.with_order_cycles_outer.
where('(product_distributions.product_id IS NOT NULL AND spree_products.deleted_at IS NULL AND spree_products.available_on <= ?) OR order_cycles.id IS NOT NULL', Time.now).
where('(product_distributions.product_id IS NOT NULL AND spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0) OR order_cycles.id IS NOT NULL', Time.now).
select('DISTINCT enterprises.*')
}

View File

@@ -37,7 +37,11 @@ describe Enterprise do
Enterprise.active_distributors.should be_empty
end
it "doesn't show distributors of out of stock products"
it "doesn't show distributors of out of stock products" do
d = create(:distributor_enterprise)
create(:product, :distributors => [d], :on_hand => 0)
Enterprise.active_distributors.should be_empty
end
it "finds active distributors by order cycles" do
s = create(:supplier_enterprise)