diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 4895fff96..ab22e6bc5 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -101,6 +101,14 @@ class FormHandler @forms = get_all_forms end + def earliest_open_collection_start_date(now: Time.zone.now) + if in_crossover_period?(now:) + collection_start_date(now) - 1.year + else + collection_start_date(now) + end + end + private def get_all_forms diff --git a/app/models/location.rb b/app/models/location.rb index afbd35a0d..3f5c35915 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -70,11 +70,7 @@ class Location < ApplicationRecord def available_from return startdate if startdate.present? - if FormHandler.instance.in_crossover_period?(now: created_at) - FormHandler.instance.collection_start_date(created_at) - 1.year - else - FormHandler.instance.collection_start_date(created_at) - end + FormHandler.instance.earliest_open_collection_start_date(now: created_at) end def open_deactivation diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 3b2c98055..b94ed53cf 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -219,11 +219,7 @@ class Scheme < ApplicationRecord end def available_from - if FormHandler.instance.in_crossover_period?(now: created_at) - FormHandler.instance.collection_start_date(created_at) - 1.year - else - FormHandler.instance.collection_start_date(created_at) - end + FormHandler.instance.earliest_open_collection_start_date(now: created_at) end def open_deactivation diff --git a/app/views/locations/toggle_active.html.erb b/app/views/locations/toggle_active.html.erb index 909b335e0..5c030de89 100644 --- a/app/views/locations/toggle_active.html.erb +++ b/app/views/locations/toggle_active.html.erb @@ -11,7 +11,7 @@ <%= form_with model: @location_deactivation_period, url: toggle_location_form_path(action, @location), method: "patch", local: true do |f| %>