From d9a9846ef00caecb4c08b6e4549c31bcd286cd6f Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:12:43 +0100 Subject: [PATCH] Change location active scope --- app/models/location.rb | 3 +-- app/models/scheme.rb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/location.rb b/app/models/location.rb index e0b996ac0..2b652c659 100644 --- a/app/models/location.rb +++ b/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)) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index ff10c33c2..07ec14731 100644 --- a/app/models/scheme.rb +++ b/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?