mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Enterprise.active_distributors doesn't show distributors from inactive order cycles
This commit is contained in:
@@ -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.*')
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user