Browse Source

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
pull/853/head
David May-Miller 3 years ago
parent
commit
e658daba56
  1. 12
      app/models/validations/date_validations.rb
  2. 2
      config/forms/2021_2022.json

12
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

2
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",

Loading…
Cancel
Save