Remove unused scope Enterprise.active_distributors

Working on the Spree upgrade, we found that this scope is using the soon
obsolete column `spree_products.count_on_hand`. Trying to measure the
impact of changing this scope, I couldn't find any use of it.

There is a variable called `active_distributors` used when serialising
enterprises, but that variable is initialised with
`Enterprise.distributors_with_active_order_cycles.ready_for_checkout`,
not using the `active_distributors` scope.

See also:
https://github.com/openfoodfoundation/openfoodnetwork/issues/2013
This commit is contained in:
Maikel Linke
2018-06-27 11:12:54 +10:00
parent eb9064f5be
commit 792701297b
2 changed files with 0 additions and 48 deletions

View File

@@ -129,12 +129,6 @@ class Enterprise < ActiveRecord::Base
joins('LEFT OUTER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
joins('LEFT OUTER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)')
scope :active_distributors, lambda {
with_distributed_products_outer.with_order_cycles_as_distributor_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 AND order_cycles.orders_open_at <= ? AND order_cycles.orders_close_at >= ?)', Time.zone.now, Time.zone.now, Time.zone.now).
select('DISTINCT enterprises.*')
}
scope :distributors_with_active_order_cycles, lambda {
with_order_cycles_as_distributor_outer.
merge(OrderCycle.active).

View File

@@ -321,48 +321,6 @@ describe Enterprise do
end
end
describe "active_distributors" do
it "finds active distributors by product distributions" do
d = create(:distributor_enterprise)
create(:product, :distributors => [d])
Enterprise.active_distributors.should == [d]
end
it "doesn't show distributors of deleted products" do
d = create(:distributor_enterprise)
create(:product, :distributors => [d], :deleted_at => Time.zone.now)
Enterprise.active_distributors.should be_empty
end
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" 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)
d = create(:distributor_enterprise)
p = create(:product)
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master])
Enterprise.active_distributors.should == [d]
end
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
describe "supplying_variant_in" do
it "finds producers by supply of master variant" do
s = create(:supplier_enterprise)