From e658daba569e855ce0f47d5f3cc955ec2d1eb4f1 Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Wed, 31 Aug 2022 15:12:21 +0100 Subject: [PATCH] CLDC-1428 Add validation preventing logs created after the first collection window's end date from having a tenancy start date in that collection window Also set the 2021/22 end date to be 1st September 2022 as a placeholder --- app/models/validations/date_validations.rb | 12 ++++++++++++ config/forms/2021_2022.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 6351a712b..ac22e8cc4 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -31,6 +31,10 @@ module Validations::DateValidations def validate_startdate(record) return unless record.startdate && date_valid?("startdate", record) + if record.created_at > first_collection_end_date && record.startdate < second_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 record.errors.add :startdate, I18n.t("validations.date.outside_collection_window") end @@ -57,6 +61,14 @@ private @first_collection_start_date ||= FormHandler.instance.forms.map { |form| form.second.start_date }.compact.min end + def first_collection_end_date + @first_collection_end_date ||= FormHandler.instance.forms.map { |form| form.second.end_date }.compact.min + end + + def second_collection_start_date + @second_collection_start_date ||= FormHandler.instance.forms.map { |form| form.second.start_date }.compact.max + end + def second_collection_end_date @second_collection_end_date ||= FormHandler.instance.forms.map { |form| form.second.end_date }.compact.max end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 1ffbc1228..4a8610935 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1,7 +1,7 @@ { "form_type": "lettings", "start_date": "2021-04-01T00:00:00.000+01:00", - "end_date": "2022-07-01T00:00:00.000+01:00", + "end_date": "2022-09-01T00:00:00.000+01:00", "sections": { "tenancy_and_property": { "label": "Property and tenancy information",