Enterprise.active_distributors doesn't show distributors from inactive order cycles

This commit is contained in:
Rohan Mitchell
2013-03-08 16:54:22 +11:00
parent 2a890f80f4
commit b25dcaa92b
2 changed files with 8 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 <= ? AND spree_products.count_on_hand > 0) 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 AND order_cycles.orders_open_at <= ? AND order_cycles.orders_close_at >= ?)', Time.now, Time.now, Time.now).
select('DISTINCT enterprises.*')
}

View File

@@ -51,7 +51,13 @@ describe Enterprise do
Enterprise.active_distributors.should == [d]
end
it "doesn't show distributors from inactive order cycles"
it "doesn't show distributors from inactive order cycles" do
s = create(:supplier_enterprise)
d = create(:distributor_enterprise)
p = create(:product)
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master], orders_open_at: 1.week.from_now, orders_close_at: 2.weeks.from_now)
Enterprise.active_distributors.should be_empty
end
end