Browse Source

Change location active scope

pull/2510/head
Manny Dinssa 2 years ago
parent
commit
d9a9846ef0
  1. 3
      app/models/location.rb
  2. 4
      app/models/scheme.rb

3
app/models/location.rb

@ -22,7 +22,6 @@ class Location < ApplicationRecord
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) }
scope :started, -> { where("locations.startdate <= ?", Time.zone.today).or(where(startdate: nil)) }
scope :active, -> { where(confirmed: true).and(started) }
scope :started_in_2_weeks, -> { where("locations.startdate <= ?", Time.zone.today + 2.weeks).or(where(startdate: nil)) }
scope :active_in_2_weeks, -> { where(confirmed: true).and(started_in_2_weeks) }
scope :confirmed, -> { where(confirmed: true) }
@ -92,7 +91,7 @@ class Location < ApplicationRecord
.where.not(id: activating_soon.pluck(:id))
}
scope :active_on_date, lambda { |date = Time.zone.now|
scope :active, lambda { |date = Time.zone.now|
where.not(id: joins(:location_deactivation_periods).reactivating_soon(date).pluck(:id))
.where.not(id: joins(scheme: [:owning_organisation]).deactivated_by_organisation.pluck(:id))
.where.not(id: joins(:location_deactivation_periods).deactivated_directly(date).pluck(:id))

4
app/models/scheme.rb

@ -296,13 +296,13 @@ class Scheme < ApplicationRecord
end
def has_active_locations?
locations.active_status.exists?
locations.active.exists?
end
def has_active_locations_on_date?(date)
return false unless date
locations.active_on_date(date).exists?
locations.active(date).exists?
end
def reactivating_soon?

Loading…
Cancel
Save