Remove distinct from enterprise.ready_for_checkout scope

Adapt use of enterprise scope not_ready_for_checkout to rails 4 by adding enterprises table alias to selected field id
This commit is contained in:
luisramos0
2019-04-06 17:45:44 +01:00
parent 9548f5c5f7
commit 0cdb49818d
2 changed files with 3 additions and 3 deletions

View File

@@ -52,7 +52,7 @@ Spree::Admin::BaseController.class_eval do
def active_distributors_not_ready_for_checkout
ocs = OrderCycle.managed_by(spree_current_user).active
distributors = ocs.map(&:distributors).flatten.uniq
Enterprise.where('id IN (?)', distributors).not_ready_for_checkout
Enterprise.where('enterprises.id IN (?)', distributors).not_ready_for_checkout
end
def active_distributors_not_ready_for_checkout_message(distributors)

View File

@@ -111,14 +111,14 @@ class Enterprise < ActiveRecord::Base
joins(:shipping_methods).
joins(:payment_methods).
merge(Spree::PaymentMethod.available).
select('DISTINCT enterprises.id')
select('enterprises.id')
}
scope :not_ready_for_checkout, lambda {
# When ready_for_checkout is empty, return all rows when there are no enterprises ready for
# checkout.
ready_enterprises = Enterprise.ready_for_checkout
if ready_enterprises.present?
where("id NOT IN (?)", ready_enterprises)
where("enterprises.id NOT IN (?)", ready_enterprises)
else
where("TRUE")
end