Browse Source

feat: allow next collection year

CLDC-1917-allow-23/24-form
natdeanlewissoftwire 2 years ago
parent
commit
8b86a750e6
  1. 28
      app/models/validations/date_validations.rb
  2. 4
      config/initializers/feature_toggle.rb
  3. 2
      config/locales/en.yml

28
app/models/validations/date_validations.rb

@ -35,11 +35,11 @@ module Validations::DateValidations
created_at = record.created_at || Time.zone.now
if created_at > first_collection_end_date && record.startdate < second_collection_start_date
if created_at > previous_collection_end_date && record.startdate < current_collection_start_date
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end
if (record.startdate < first_collection_start_date || record.startdate > second_collection_end_date) && FeatureToggle.startdate_collection_window_validation_enabled?
if (record.startdate < previous_collection_start_date || record.startdate > next_collection_end_date)
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end
@ -68,20 +68,28 @@ module Validations::DateValidations
private
def first_collection_start_date
@first_collection_start_date ||= FormHandler.instance.lettings_forms["previous_lettings"].start_date
def previous_collection_start_date
@previous_collection_start_date ||= FormHandler.instance.lettings_forms["previous_lettings"].start_date
end
def first_collection_end_date
@first_collection_end_date ||= FormHandler.instance.lettings_forms["previous_lettings"].end_date
def previous_collection_end_date
@previous_collection_end_date ||= FormHandler.instance.lettings_forms["previous_lettings"].end_date
end
def second_collection_start_date
@second_collection_start_date ||= FormHandler.instance.lettings_forms["current_lettings"].start_date
def current_collection_start_date
@current_collection_start_date ||= FormHandler.instance.lettings_forms["current_lettings"].start_date
end
def second_collection_end_date
@second_collection_end_date ||= FormHandler.instance.lettings_forms["current_lettings"].end_date
def current_collection_end_date
@current_collection_end_date ||= FormHandler.instance.lettings_forms["current_lettings"].end_date
end
def next_collection_start_date
@next_collection_start_date ||= FormHandler.instance.lettings_forms["next_lettings"].start_date
end
def next_collection_end_date
@next_collection_end_date ||= FormHandler.instance.lettings_forms["next_lettings"].end_date
end
def is_rsnvac_first_let?(record)

4
config/initializers/feature_toggle.rb

@ -3,10 +3,6 @@ class FeatureToggle
Rails.env.production? || Rails.env.test?
end
def self.startdate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test?
end
def self.saledate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test?
end

2
config/locales/en.yml

@ -136,7 +136,7 @@ en:
above_min: "%{field} must be at least %{min}"
date:
invalid_date: "Enter a date in the correct format, for example 31 1 2022"
outside_collection_window: Enter a date within the 22/23 financial year, which is between 1st April 2022 and 31st March 2023
outside_collection_window: "Enter a date within the 22/23 or 23/24 financial years, which is between 1st April 2022 and 31st March 2024"
postcode: "Enter a postcode in the correct format, for example AA1 1AA"
location_admin_district: "Select a local authority"
email:

Loading…
Cancel
Save