diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 3a7350a8a..d4a549b86 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -32,7 +32,7 @@ module DerivedVariables::LettingsLogVariables def scheme_has_multiple_locations? return false unless scheme - @scheme_locations_count ||= scheme.locations.active.size + @scheme_locations_count ||= scheme.locations.active_in_2_weeks.size @scheme_locations_count > 1 end diff --git a/app/models/form/lettings/questions/location_id.rb b/app/models/form/lettings/questions/location_id.rb index 80c2516e8..7e022b69c 100644 --- a/app/models/form/lettings/questions/location_id.rb +++ b/app/models/form/lettings/questions/location_id.rb @@ -19,8 +19,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question answer_opts = {} return answer_opts unless ActiveRecord::Base.connected? - Location.select(:id, :postcode, :name).where("startdate <= ? or startdate IS NULL", - Time.zone.today).each_with_object(answer_opts) do |location, hsh| + Location.started_in_2_weeks.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh| hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name } hsh end @@ -29,7 +28,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question def displayed_answer_options(lettings_log, _user = nil) return {} unless lettings_log.scheme - scheme_location_ids = lettings_log.scheme.locations.confirmed.pluck(:id) + scheme_location_ids = lettings_log.scheme.locations.pluck(:id) answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) } end diff --git a/app/models/form/lettings/questions/scheme_id.rb b/app/models/form/lettings/questions/scheme_id.rb index 20bda8412..5d140b21b 100644 --- a/app/models/form/lettings/questions/scheme_id.rb +++ b/app/models/form/lettings/questions/scheme_id.rb @@ -35,8 +35,7 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question else Scheme.includes(:locations).select(:id).where(confirmed: true) end - filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", - Time.zone.today)).map(&:id) + filtered_scheme_ids = schemes.joins(:locations).merge(Location.started_in_2_weeks).map(&:id) answer_options.select do |k, _v| filtered_scheme_ids.include?(k.to_i) || k.blank? end diff --git a/app/models/location.rb b/app/models/location.rb index 818ea5700..0dd6ba522 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -23,6 +23,8 @@ class Location < ApplicationRecord scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } scope :started, -> { where("startdate <= ?", Time.zone.today).or(where(startdate: nil)) } scope :active, -> { where(confirmed: true).and(started) } + scope :started_in_2_weeks, -> { where("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) } scope :unconfirmed, -> { where.not(confirmed: true) }