Enterprise.active_distributors doesn't show distributors of unavailable products

This commit is contained in:
Rohan Mitchell
2013-03-08 16:46:25 +11:00
parent cd61bad0b9
commit 13abf9ada7
2 changed files with 10 additions and 3 deletions

View File

@@ -33,9 +33,11 @@ class Enterprise < ActiveRecord::Base
joins('LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id)').
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :active_distributors, with_distributed_products_outer.with_order_cycles_outer.
where('(product_distributions.product_id IS NOT NULL AND spree_products.deleted_at IS NULL) OR order_cycles.id IS NOT NULL').
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).
select('DISTINCT enterprises.*')
}
def has_supplied_products_on_hand?

View File

@@ -31,7 +31,12 @@ describe Enterprise do
Enterprise.active_distributors.should be_empty
end
it "doesn't show distributors of unavailable products"
it "doesn't show distributors of unavailable products" do
d = create(:distributor_enterprise)
create(:product, :distributors => [d], :available_on => 1.week.from_now)
Enterprise.active_distributors.should be_empty
end
it "doesn't show distributors of out of stock products"
it "finds active distributors by order cycles" do