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 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") record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end 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") record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end end
@ -68,20 +68,28 @@ module Validations::DateValidations
private private
def first_collection_start_date def previous_collection_start_date
@first_collection_start_date ||= FormHandler.instance.lettings_forms["previous_lettings"].start_date @previous_collection_start_date ||= FormHandler.instance.lettings_forms["previous_lettings"].start_date
end end
def first_collection_end_date def previous_collection_end_date
@first_collection_end_date ||= FormHandler.instance.lettings_forms["previous_lettings"].end_date @previous_collection_end_date ||= FormHandler.instance.lettings_forms["previous_lettings"].end_date
end end
def second_collection_start_date def current_collection_start_date
@second_collection_start_date ||= FormHandler.instance.lettings_forms["current_lettings"].start_date @current_collection_start_date ||= FormHandler.instance.lettings_forms["current_lettings"].start_date
end end
def second_collection_end_date def current_collection_end_date
@second_collection_end_date ||= FormHandler.instance.lettings_forms["current_lettings"].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 end
def is_rsnvac_first_let?(record) def is_rsnvac_first_let?(record)

4
config/initializers/feature_toggle.rb

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

2
config/locales/en.yml

@ -136,7 +136,7 @@ en:
above_min: "%{field} must be at least %{min}" above_min: "%{field} must be at least %{min}"
date: date:
invalid_date: "Enter a date in the correct format, for example 31 1 2022" 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" postcode: "Enter a postcode in the correct format, for example AA1 1AA"
location_admin_district: "Select a local authority" location_admin_district: "Select a local authority"
email: email:

Loading…
Cancel
Save