mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Enterprise.active_distributors doesn't show distributors of unavailable products
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user