Browse Source

feat: add separate validations for crossover and non-crossover

CLDC-1917-allow-23/24-form
natdeanlewissoftwire 2 years ago
parent
commit
98dc083e1a
  1. 23
      app/models/validations/date_validations.rb
  2. 4
      config/locales/en.yml

23
app/models/validations/date_validations.rb

@ -35,12 +35,15 @@ module Validations::DateValidations
created_at = record.created_at || Time.zone.now
if created_at > previous_collection_end_date && record.startdate < current_collection_start_date
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
#add 1-year error if log created outside crossover period, and outside 1 year window
#add 2-year error if log created in crossover period, and outside of 2 year window
if created_at > previous_collection_end_date && !record.startdate.between?(current_collection_start_date, current_collection_end_date)
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window.not_crossover_period", current_collection: "#{current_collection_start_suffix}/#{current_collection_start_suffix + 1}", current_collection_start_year: current_collection_start_date.year, current_collection_end_year: current_collection_end_date.year)
end
if (record.startdate < previous_collection_start_date || record.startdate > next_collection_end_date)
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
if created_at < previous_collection_end_date && !record.startdate.between?(previous_collection_start_date, current_collection_end_date)
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window.crossover_period", previous_collection: "#{current_collection_start_suffix - 1}/#{current_collection_start_suffix}", current_collection: "#{current_collection_start_suffix}/#{current_collection_start_suffix + 1}", previous_collection_start_year: previous_collection_start_date.year, current_collection_end_year: current_collection_end_date.year)
end
if FeatureToggle.startdate_two_week_validation_enabled? && record.startdate > Time.zone.today + 14
@ -68,6 +71,10 @@ module Validations::DateValidations
private
def current_collection_start_suffix
current_collection_start_date.strftime("%y").to_i
end
def previous_collection_start_date
@previous_collection_start_date ||= FormHandler.instance.lettings_forms["previous_lettings"].start_date
end
@ -84,14 +91,6 @@ private
@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)
[15, 16, 17].include?(record["rsnvac"])
end

4
config/locales/en.yml

@ -136,7 +136,9 @@ 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 or 23/24 financial years, which is between 1st April 2022 and 31st March 2024"
outside_collection_window:
crossover_period: "Enter a date within the %{previous_collection} or %{current_collection} financial years, which is between 1st April %{previous_collection_start_year} and 31st March %{current_collection_end_year}"
not_crossover_period: "Enter a date within the %{current_collection} financial year, which is between 1st April %{current_collection_start_year} and 31st March %{current_collection_end_year}"
postcode: "Enter a postcode in the correct format, for example AA1 1AA"
location_admin_district: "Select a local authority"
email:

Loading…
Cancel
Save