From abf83b0e584c8c8477db28ccbdd13604a056113e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 26 Mar 2014 12:07:06 +1100 Subject: [PATCH] Find only outgoing exchanges for Enterprise scopes using with_order_cycles_outer --- app/models/enterprise.rb | 2 +- spec/models/enterprise_spec.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 501f18f4a7..9d63cdd25a 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -47,7 +47,7 @@ class Enterprise < ActiveRecord::Base joins('LEFT OUTER JOIN product_distributions ON product_distributions.distributor_id = enterprises.id'). joins('LEFT OUTER JOIN spree_products ON spree_products.id = product_distributions.product_id') scope :with_order_cycles_outer, - joins('LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id)'). + joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')"). joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)') scope :with_order_cycles_and_exchange_variants_outer, diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 98e7a90f7b..8f562b947b 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -106,7 +106,6 @@ describe Enterprise do 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 "with_distributed_active_products_on_hand" do