Files
openfoodnetwork/app/helpers/admin/subscriptions_helper.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

25 lines
691 B
Ruby

# frozen_string_literal: true
module Admin
module SubscriptionsHelper
def subscriptions_setup_complete?(shops)
return false unless shops.any?
shops = shops.select{ |shop| shipping_and_payment_methods_ok?(shop) && customers_ok?(shop) }
Schedule.joins(:order_cycles).where(order_cycles: { coordinator_id: shops }).any?
end
def shipping_and_payment_methods_ok?(shop)
shop.present? && shop.shipping_methods.any? && shop.payment_methods.for_subscriptions.any?
end
def customers_ok?(shop)
shop.present? && shop.customers.any?
end
def schedules_ok?(shop)
shop.present? && Schedule.with_coordinator(shop).any?
end
end
end