diff --git a/app/services/permissions/order.rb b/app/services/permissions/order.rb index 8dbbca41be..94ec900e0c 100644 --- a/app/services/permissions/order.rb +++ b/app/services/permissions/order.rb @@ -63,28 +63,36 @@ module Permissions # Any orders placed through any hub that I manage def managed_orders_where_values - Spree::Order. - where(distributor_id: @permissions.managed_enterprises.select("enterprises.id")). - where_clause.__send__(:predicates). - reduce(:and) + query = Spree::Order. + where(distributor_id: @permissions.managed_enterprises.select("enterprises.id")) + + apply_where_clause(query).reduce(:and) end # Any order that is placed through an order cycle one of my managed enterprises coordinates def coordinated_orders_where_values - Spree::Order. - where(order_cycle_id: @permissions.coordinated_order_cycles.select(:id)). - where_clause.__send__(:predicates). - reduce(:and) + query = Spree::Order. + where(order_cycle_id: @permissions.coordinated_order_cycles.select(:id)) + + apply_where_clause(query).reduce(:and) end def produced_orders_where_values - Spree::Order.with_line_items_variants_and_products_outer. + query = Spree::Order.with_line_items_variants_and_products_outer. where( distributor_id: granted_distributor_ids, spree_products: { supplier_id: enterprises_with_associated_orders } - ). - where_clause.__send__(:predicates). - reduce(:and) + ) + + apply_where_clause(query).reduce(:and) + end + + def apply_where_clause(query) + if ENV['DEPENDENCIES_NEXT'] + query = query.where_clause.__send__(:predicates) + else + query = query.where_values + end end def enterprises_with_associated_orders