Refactor "active outgoing variants"

This commit is contained in:
Matt-Yorkley
2019-08-07 17:45:07 +01:00
committed by luisramos0
parent ed15bc422e
commit ca5ecc4696

View File

@@ -182,11 +182,7 @@ module OpenFoodNetwork
hub_variants = Spree::Variant.joins(:product).where('spree_products.supplier_id = (?)', hub)
# PLUS variants that are already in an outgoing exchange of this hub, so things don't break
# TODO: Remove this when all P-OC are sorted out
active_variants = []
@order_cycle.exchanges.outgoing.where(receiver_id: hub).limit(1).each do |exchange|
active_variants = exchange.variants
end
active_variants = active_outgoing_variants(hub)
Spree::Variant.
where(id: coordinator_variants | hub_variants | permitted_variants | active_variants)
@@ -234,11 +230,7 @@ module OpenFoodNetwork
hub_variants = Spree::Variant.joins(:product).where('spree_products.supplier_id = (?)', hub)
# PLUS variants that are already in an outgoing exchange of this hub, so things don't break
# TODO: Remove this when all P-OC are sorted out
active_variants = []
@order_cycle.exchanges.outgoing.where(receiver_id: hub).limit(1).each do |exchange|
active_variants = exchange.variants
end
active_variants = active_outgoing_variants(hub)
Spree::Variant.
where(id: coordinator_variants | hub_variants | permitted_variants | active_variants)
@@ -262,6 +254,14 @@ module OpenFoodNetwork
private
def active_outgoing_variants(hub)
active_variants = []
@order_cycle.exchanges.outgoing.where(receiver_id: hub).limit(1).each do |exchange|
active_variants = exchange.variants
end
active_variants
end
def user_manages_coordinator_or(enterprise)
managed_enterprises.pluck(:id).include?(@coordinator.id) ||
managed_enterprises.pluck(:id).include?(enterprise.id)