diff --git a/app/models/form.rb b/app/models/form.rb index a13cdcfaa..426f4e21c 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -1,16 +1,16 @@ class Form attr_reader :form_definition, :sections, :subsections, :pages, :questions, - :start_date, :end_date, :submission_deadline, :type, :name, :setup_definition, + :start_date, :new_logs_end_date, :submission_deadline, :type, :name, :setup_definition, :setup_sections, :form_sections, :unresolved_log_redirect_page_id, :edit_end_date def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings") if sales_or_start_year_after_2022?(type, start_year) @start_date = Time.zone.local(start_year, 4, 1) - @end_date = if start_year && start_year.to_i > 2022 - Time.zone.local(start_year + 1, 6, 9) - else - Time.zone.local(start_year + 1, 8, 7) - end + @new_logs_end_date = if start_year && start_year.to_i > 2022 + Time.zone.local(start_year + 1, 6, 9) + else + Time.zone.local(start_year + 1, 8, 7) + end @submission_deadline = if start_year && start_year.to_i > 2022 Time.zone.local(start_year + 1, 6, 7) else @@ -26,7 +26,7 @@ class Form @form_definition = { "form_type" => type, "start_date" => start_date, - "end_date" => end_date, + "end_date" => new_logs_end_date, "sections" => sections, } @unresolved_log_redirect_page_id = "tenancy_start_date" if type == "lettings" @@ -42,12 +42,12 @@ class Form @pages = subsections.flat_map(&:pages) @questions = pages.flat_map(&:questions) @start_date = Time.iso8601(form_definition["start_date"]) - @end_date = Time.iso8601(form_definition["end_date"]) + @new_logs_end_date = Time.iso8601(form_definition["end_date"]) @submission_deadline = Time.zone.local(2023, 6, 9) @unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"] end - @edit_end_date = @end_date - @name = "#{start_date.year}_#{end_date.year}_#{type}" + @edit_end_date = @new_logs_end_date + @name = "#{start_date.year}_#{new_logs_end_date.year}_#{type}" end def get_subsection(id) @@ -304,7 +304,7 @@ class Form end def valid_start_date_for_form?(start_date) - start_date >= self.start_date && start_date <= end_date + start_date >= self.start_date && start_date <= new_logs_end_date end def sales_or_start_year_after_2022?(type, start_year) diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index c596e8b54..50a28fc18 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -109,12 +109,12 @@ class FormHandler def lettings_in_crossover_period?(now: Time.zone.now) forms = lettings_forms.values - forms.count { |form| now.between?(form.start_date, form.end_date) } > 1 + forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1 end def sales_in_crossover_period?(now: Time.zone.now) forms = sales_forms.values - forms.count { |form| now.between?(form.start_date, form.end_date) } > 1 + forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1 end def use_fake_forms!(fake_forms = nil) diff --git a/app/models/log.rb b/app/models/log.rb index d394c0360..583556e1d 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -94,7 +94,7 @@ class Log < ApplicationRecord def collection_period_open? return false if older_than_previous_collection_year? - form.end_date > Time.zone.today + form.new_logs_end_date > Time.zone.today end def blank_invalid_non_setup_fields! diff --git a/app/services/bulk_upload/lettings/year2022/csv_parser.rb b/app/services/bulk_upload/lettings/year2022/csv_parser.rb index f21e92a24..9e672ade5 100644 --- a/app/services/bulk_upload/lettings/year2022/csv_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/csv_parser.rb @@ -63,7 +63,7 @@ class BulkUpload::Lettings::Year2022::CsvParser end def wrong_template_for_year? - !(first_record_start_date >= form.start_date && first_record_start_date <= form.end_date) + !(first_record_start_date >= form.start_date && first_record_start_date <= form.new_logs_end_date) end private diff --git a/app/services/bulk_upload/sales/year2022/csv_parser.rb b/app/services/bulk_upload/sales/year2022/csv_parser.rb index 939ff5689..d14284f50 100644 --- a/app/services/bulk_upload/sales/year2022/csv_parser.rb +++ b/app/services/bulk_upload/sales/year2022/csv_parser.rb @@ -45,7 +45,7 @@ class BulkUpload::Sales::Year2022::CsvParser end def wrong_template_for_year? - !(first_record_sale_date >= form.start_date && first_record_sale_date <= form.end_date) + !(first_record_sale_date >= form.start_date && first_record_sale_date <= form.new_logs_end_date) end private diff --git a/docs/adr/adr-019-form-end-dates.md b/docs/adr/adr-019-form-end-dates.md index f3f802693..6f7f87c66 100644 --- a/docs/adr/adr-019-form-end-dates.md +++ b/docs/adr/adr-019-form-end-dates.md @@ -13,5 +13,5 @@ Also, if incorrect data is found during QA process, data providers might be aske To accommodate the different end dates, we will now store 3 different dates on the form definition: - Submission deadline (submission_deadline) - this is the date displayed at the top of a completed log in lettings and sales - "You can review and make changes to this log until 9 June 2024.". Nothing happens on this date -- New logs end date (end_date) - no new logs for that collection year can be submitted, but logs can be edited +- New logs end date (new_logs_end_date) - no new logs for that collection year can be submitted, but logs can be edited - Edit and delete logs end date (edit_end_date) - logs can no longer be edited or deleted. Completed logs can still be viewed. Materials / references to the collection year are removed. diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb index 0ff03ec03..18f7c3411 100644 --- a/spec/features/form/accessible_autocomplete_spec.rb +++ b/spec/features/form/accessible_autocomplete_spec.rb @@ -28,7 +28,7 @@ RSpec.describe "Accessible Autocomplete" do end before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user end diff --git a/spec/features/form/check_answers_page_lettings_logs_spec.rb b/spec/features/form/check_answers_page_lettings_logs_spec.rb index 97a9ccbec..8b774c802 100644 --- a/spec/features/form/check_answers_page_lettings_logs_spec.rb +++ b/spec/features/form/check_answers_page_lettings_logs_spec.rb @@ -51,8 +51,8 @@ RSpec.describe "Lettings Log Check Answers Page" do let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) - allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) + allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) end diff --git a/spec/features/form/checkboxes_spec.rb b/spec/features/form/checkboxes_spec.rb index dae505bcf..3ad2ca0cf 100644 --- a/spec/features/form/checkboxes_spec.rb +++ b/spec/features/form/checkboxes_spec.rb @@ -24,7 +24,7 @@ RSpec.describe "Checkboxes" do end before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) RequestHelper.stub_http_requests sign_in user end diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index f79b33191..ffa46dfaf 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -33,8 +33,8 @@ RSpec.describe "Form Conditional Questions" do before do sign_in user - allow(sales_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(sales_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) end diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index 6fdec8366..9a9f14383 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -44,8 +44,8 @@ RSpec.describe "Form Navigation" do let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) - allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) + allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) end diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index 98c370cff..e6c821221 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -15,7 +15,7 @@ RSpec.describe "Form Page Routing" do let(:validator) { lettings_log._validators[nil].first } before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user end diff --git a/spec/features/form/progressive_total_field_spec.rb b/spec/features/form/progressive_total_field_spec.rb index cbf50f206..a3c52569d 100644 --- a/spec/features/form/progressive_total_field_spec.rb +++ b/spec/features/form/progressive_total_field_spec.rb @@ -22,7 +22,7 @@ RSpec.describe "Accessible Autocomplete" do end before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user end diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index 0c7397511..c1d051a7e 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -37,7 +37,7 @@ RSpec.describe "Form Saving Data" do end before do - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user end diff --git a/spec/features/form/tasklist_page_spec.rb b/spec/features/form/tasklist_page_spec.rb index a97c7accd..5b7dd351f 100644 --- a/spec/features/form/tasklist_page_spec.rb +++ b/spec/features/form/tasklist_page_spec.rb @@ -54,7 +54,7 @@ RSpec.describe "Task List" do before do Timecop.freeze(Time.zone.local(2021, 5, 1)) setup_completed_log.update!(startdate: Time.zone.local(2021, 5, 1)) - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user end diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 420114129..a14754e5e 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -42,8 +42,8 @@ RSpec.describe "validations" do let(:id) { lettings_log.id } before do - allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day) - allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) + allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) sign_in user allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 439cd24b1..f413e6a7e 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -371,7 +371,9 @@ RSpec.describe Form, type: :model do expect(form.questions.count).to eq(13) expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) - expect(form.end_date).to eq(Time.zone.parse("2023-08-07")) + expect(form.new_logs_end_date).to eq(Time.zone.parse("2023-08-07")) + expect(form.edit_end_date).to eq(Time.zone.parse("2023-08-07")) + expect(form.submission_deadline).to eq(Time.zone.parse("2023-06-09")) expect(form.unresolved_log_redirect_page_id).to eq(nil) end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 74abfd3c2..f050e7fcd 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -3040,7 +3040,7 @@ RSpec.describe LettingsLog do let(:startdate) { nil } before do - allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now + 1.day) + allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now + 1.day) end it "returns true" do @@ -3052,7 +3052,7 @@ RSpec.describe LettingsLog do let(:startdate) { Time.zone.local(2020, 4, 1) } before do - allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now - 1.day) + allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now - 1.day) end it "returns false" do diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index f2337b84d..ef197235f 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -635,7 +635,7 @@ RSpec.describe SalesLog, type: :model do let(:saledate) { nil } before do - allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now + 1.day) + allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now + 1.day) end it "returns true" do @@ -647,7 +647,7 @@ RSpec.describe SalesLog, type: :model do let(:saledate) { Time.zone.local(2020, 4, 1) } before do - allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now - 1.day) + allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now - 1.day) end it "returns false" do diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index a2c06c4f1..f8be6edff 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -31,7 +31,7 @@ RSpec.describe FormController, type: :request do let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } before do - allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) end @@ -763,7 +763,7 @@ RSpec.describe FormController, type: :request do before do completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1) # we're not routing to that page, so it gets cleared? allow(completed_lettings_log).to receive(:net_income_soft_validation_triggered?).and_return(true) - allow(completed_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(completed_lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) post "/lettings-logs/#{completed_lettings_log.id}/net-income-value-check", params: interrupt_params, headers: headers.merge({ "HTTP_REFERER" => referrer }) end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 50c4d6763..0f5344435 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -937,14 +937,14 @@ RSpec.describe LettingsLogsController, type: :request do completed_lettings_log.reload get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} - expect(completed_lettings_log.form.end_date).to eq(Time.zone.local(2023, 7, 1)) + expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2023, 7, 1)) expect(completed_lettings_log.status).to eq("completed") expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review") end xit "displays a closed collection window message for previous collection year logs" do get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} - expect(completed_lettings_log.form.end_date).to eq(Time.zone.local(2022, 7, 1)) + expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 7, 1)) expect(completed_lettings_log.status).to eq("completed") expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.") end @@ -1198,7 +1198,7 @@ RSpec.describe LettingsLogsController, type: :request do let(:headers) { { "Accept" => "text/html" } } before do - allow(affected_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) + allow(affected_lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day) allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user end