diff --git a/lib/open_food_network/order_cycle_permissions.rb b/lib/open_food_network/order_cycle_permissions.rb index 73264ce414..cb907fcc07 100644 --- a/lib/open_food_network/order_cycle_permissions.rb +++ b/lib/open_food_network/order_cycle_permissions.rb @@ -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)