diff --git a/Dockerfile b/Dockerfile index 814582011..c1a5e7cc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN apk add --update --no-cache tzdata && \ # build-base: compilation tools for bundle # yarn: node package manager # postgresql-dev: postgres driver and libraries -RUN apk add --no-cache build-base=0.5-r3 busybox=1.36.1-r7 nodejs-current=20.8.1-r0 yarn=1.22.19-r0 postgresql13-dev=13.18-r0 git=2.40.3-r0 bash=5.2.15-r5 +RUN apk add --no-cache build-base=0.5-r3 busybox=1.36.1-r7 nodejs-current=20.8.1-r0 yarn=1.22.19-r0 postgresql13-dev=13.18-r0 bash=5.2.15-r5 # Bundler version should be the same version as what the Gemfile.lock was bundled with RUN gem install bundler:2.3.14 --no-document diff --git a/app/components/create_log_actions_component.html.erb b/app/components/create_log_actions_component.html.erb index a600f3290..4b74c8901 100644 --- a/app/components/create_log_actions_component.html.erb +++ b/app/components/create_log_actions_component.html.erb @@ -9,8 +9,9 @@ <% end %> <% if FeatureToggle.create_test_logs_enabled? %> - <%= govuk_button_link_to "Create test log", create_test_log_href, secondary: true %> - <%= govuk_button_link_to "Create test log (setup only)", create_setup_test_log_href, secondary: true %> + <%= govuk_link_to "Create test log", create_test_log_href %> + <%= govuk_link_to "Create test log (setup only)", create_setup_test_log_href %> + <%= govuk_link_to "Get test BU file (2024)", create_2024_test_bulk_upload_href %> <% end %> <% end %> diff --git a/app/components/create_log_actions_component.rb b/app/components/create_log_actions_component.rb index 896bfe97e..0abbfd385 100644 --- a/app/components/create_log_actions_component.rb +++ b/app/components/create_log_actions_component.rb @@ -42,6 +42,10 @@ class CreateLogActionsComponent < ViewComponent::Base send("create_setup_test_#{log_type}_log_path") end + def create_2024_test_bulk_upload_href + send("create_2024_test_#{log_type}_bulk_upload_path") + end + def view_uploads_button_copy "View #{log_type} bulk uploads" end diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb index 39bc05f7e..4acdbbcb0 100644 --- a/app/controllers/bulk_upload_lettings_logs_controller.rb +++ b/app/controllers/bulk_upload_lettings_logs_controller.rb @@ -58,15 +58,15 @@ private def form @form ||= case params[:id] when "year" - Forms::BulkUploadLettings::Year.new(form_params) + Forms::BulkUploadForm::Year.new(form_params.merge(log_type: "lettings")) when "prepare-your-file" - Forms::BulkUploadLettings::PrepareYourFile.new(form_params) + Forms::BulkUploadForm::PrepareYourFile.new(form_params.merge(log_type: "lettings")) when "guidance" - Forms::BulkUploadLettings::Guidance.new(form_params.merge(referrer: params[:referrer])) + Forms::BulkUploadForm::Guidance.new(form_params.merge(referrer: params[:referrer], log_type: "lettings")) when "upload-your-file" - Forms::BulkUploadLettings::UploadYourFile.new(form_params.merge(current_user:)) + Forms::BulkUploadForm::UploadYourFile.new(form_params.merge(current_user:, log_type: "lettings")) when "checking-file" - Forms::BulkUploadLettings::CheckingFile.new(form_params) + Forms::BulkUploadForm::CheckingFile.new(form_params.merge(log_type: "lettings")) else raise "Page not found for path #{params[:id]}" end diff --git a/app/controllers/bulk_upload_lettings_resume_controller.rb b/app/controllers/bulk_upload_lettings_resume_controller.rb index 9003c8ced..756e26baa 100644 --- a/app/controllers/bulk_upload_lettings_resume_controller.rb +++ b/app/controllers/bulk_upload_lettings_resume_controller.rb @@ -42,13 +42,13 @@ private def form @form ||= case params[:page] when "fix-choice" - Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) when "chosen" - Forms::BulkUploadLettingsResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) when "confirm" - Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) when "deletion-report" - Forms::BulkUploadLettingsResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) else raise "invalid form" end diff --git a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb index a70af3c4b..faaf60302 100644 --- a/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb +++ b/app/controllers/bulk_upload_lettings_soft_validations_check_controller.rb @@ -36,11 +36,11 @@ private def form @form ||= case params[:page] when "confirm-soft-errors" - Forms::BulkUploadLettingsSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) when "chosen" - Forms::BulkUploadLettingsSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) when "confirm" - Forms::BulkUploadLettingsSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "lettings")) else raise "invalid form" end diff --git a/app/controllers/bulk_upload_sales_logs_controller.rb b/app/controllers/bulk_upload_sales_logs_controller.rb index cb04cea95..61eb59fbd 100644 --- a/app/controllers/bulk_upload_sales_logs_controller.rb +++ b/app/controllers/bulk_upload_sales_logs_controller.rb @@ -58,15 +58,15 @@ private def form @form ||= case params[:id] when "year" - Forms::BulkUploadSales::Year.new(form_params) + Forms::BulkUploadForm::Year.new(form_params.merge(log_type: "sales")) when "prepare-your-file" - Forms::BulkUploadSales::PrepareYourFile.new(form_params) + Forms::BulkUploadForm::PrepareYourFile.new(form_params.merge(log_type: "sales")) when "guidance" - Forms::BulkUploadSales::Guidance.new(form_params.merge(referrer: params[:referrer])) + Forms::BulkUploadForm::Guidance.new(form_params.merge(referrer: params[:referrer], log_type: "sales")) when "upload-your-file" - Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:)) + Forms::BulkUploadForm::UploadYourFile.new(form_params.merge(current_user:, log_type: "sales")) when "checking-file" - Forms::BulkUploadSales::CheckingFile.new(form_params) + Forms::BulkUploadForm::CheckingFile.new(form_params.merge(log_type: "sales")) else raise "Page not found for path #{params[:id]}" end diff --git a/app/controllers/bulk_upload_sales_resume_controller.rb b/app/controllers/bulk_upload_sales_resume_controller.rb index 7514d2515..ad786f4a1 100644 --- a/app/controllers/bulk_upload_sales_resume_controller.rb +++ b/app/controllers/bulk_upload_sales_resume_controller.rb @@ -42,13 +42,13 @@ private def form @form ||= case params[:page] when "fix-choice" - Forms::BulkUploadSalesResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) when "chosen" - Forms::BulkUploadSalesResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) when "confirm" - Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) when "deletion-report" - Forms::BulkUploadSalesResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadResume::DeletionReport.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) else raise "invalid form" end diff --git a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb index 5b71b2c40..0795ad81e 100644 --- a/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb +++ b/app/controllers/bulk_upload_sales_soft_validations_check_controller.rb @@ -36,11 +36,11 @@ private def form @form ||= case params[:page] when "confirm-soft-errors" - Forms::BulkUploadSalesSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadSoftValidationsCheck::ConfirmSoftErrors.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) when "chosen" - Forms::BulkUploadSalesSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadSoftValidationsCheck::Chosen.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) when "confirm" - Forms::BulkUploadSalesSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) + Forms::BulkUploadSoftValidationsCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload, log_type: "sales")) else raise "invalid form" end diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index f31662c4f..54988e71d 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -32,6 +32,7 @@ class FormController < ApplicationController pages_requiring_update = pages_requiring_update(shown_page_ids_with_unanswered_questions_before_update) redirect_to(successful_redirect_path(pages_requiring_update)) else + @log.valid? if mandatory_questions_with_no_response.any? mandatory_questions_with_no_response.map do |question| @log.errors.add question.id.to_sym, question.unanswered_error_message, category: :not_answered end diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index 7fef9499b..38a89b682 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -149,20 +149,6 @@ class LettingsLogsController < LogsController end end - def create_test_log - return render_not_found unless FeatureToggle.create_test_logs_enabled? - - log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA") - redirect_to lettings_log_path(log) - end - - def create_setup_test_log - return render_not_found unless FeatureToggle.create_test_logs_enabled? - - log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user) - redirect_to lettings_log_path(log) - end - private def session_filters diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index 237fd94d7..3c389ccf1 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -119,20 +119,6 @@ class SalesLogsController < LogsController end end - def create_test_log - return render_not_found unless FeatureToggle.create_test_logs_enabled? - - log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user) - redirect_to sales_log_path(log) - end - - def create_setup_test_log - return render_not_found unless FeatureToggle.create_test_logs_enabled? - - log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user) - redirect_to sales_log_path(log) - end - private def session_filters diff --git a/app/controllers/test_data_controller.rb b/app/controllers/test_data_controller.rb new file mode 100644 index 000000000..2b049f176 --- /dev/null +++ b/app/controllers/test_data_controller.rb @@ -0,0 +1,68 @@ +class TestDataController < ApplicationController + rescue_from ActiveRecord::RecordNotFound, with: :render_not_found + + def create_test_lettings_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA") + redirect_to lettings_log_path(log) + end + + def create_setup_test_lettings_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user) + redirect_to lettings_log_path(log) + end + + def create_2024_test_lettings_bulk_upload + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + file = Tempfile.new("test_lettings_log.csv") + log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA") + log_to_csv = BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" }) + file.write(log_to_csv.default_field_numbers_row) + file.write(log_to_csv.to_csv_row) + file.rewind + send_file file.path, type: "text/csv", + filename: "test_lettings_log.csv", + disposition: "attachment", + after_send: lambda { + file.close + file.unlink + } + end + + def create_test_sales_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user) + redirect_to sales_log_path(log) + end + + def create_setup_test_sales_log + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user) + redirect_to sales_log_path(log) + end + + def create_2024_test_sales_bulk_upload + return render_not_found unless FeatureToggle.create_test_logs_enabled? + + file = Tempfile.new("test_sales_log.csv") + + log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000) + log_to_csv = BulkUpload::SalesLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" }) + file.write(log_to_csv.default_field_numbers_row) + file.write(log_to_csv.to_csv_row) + file.rewind + send_file file.path, type: "text/csv", + filename: "test_sales_log.csv", + disposition: "attachment", + after_send: lambda { + file.close + file.unlink + } + end +end diff --git a/app/frontend/styles/_custom-rails-admin.scss b/app/frontend/styles/_custom-rails-admin.scss new file mode 100644 index 000000000..2652b8480 --- /dev/null +++ b/app/frontend/styles/_custom-rails-admin.scss @@ -0,0 +1,34 @@ +.rails-admin-sidescroll { + overflow-x: scroll; +} + +.rails-admin-description_field { + min-width: 500px; +} + +.rails-admin-case_field { + min-width: 500px; +} + +.rails-admin-error_message_field { + min-width: 500px; +} + +.rails-admin-actions { + min-width: 160px; + + ul { + float: right; + } +} + +.rails-admin-filters-box { + .filter { + // stylelint-disable-next-line declaration-no-important + display: flex !important; + } + + button { + min-width: 20%; + } +} diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 3e75107bd..94135074e 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -48,6 +48,7 @@ $govuk-breakpoints: ( @import "search"; @import "sub-navigation"; @import "unread-notification"; +@import "custom-rails-admin"; // App utilities .app-\!-colour-muted { diff --git a/spec/support/bulk_upload/lettings_log_to_csv.rb b/app/helpers/bulk_upload/lettings_log_to_csv.rb similarity index 96% rename from spec/support/bulk_upload/lettings_log_to_csv.rb rename to app/helpers/bulk_upload/lettings_log_to_csv.rb index 18c367ffc..cdf38db17 100644 --- a/spec/support/bulk_upload/lettings_log_to_csv.rb +++ b/app/helpers/bulk_upload/lettings_log_to_csv.rb @@ -2,10 +2,12 @@ class BulkUpload::LettingsLogToCsv attr_reader :log, :line_ending, :col_offset, :overrides def initialize(log:, line_ending: "\n", col_offset: 1, overrides: {}) + # rubocop:disable Rails/HelperInstanceVariable @log = log @line_ending = line_ending @col_offset = col_offset @overrides = overrides + # rubocop:enable Rails/HelperInstanceVariable end def row_prefix @@ -145,8 +147,8 @@ class BulkUpload::LettingsLogToCsv def to_2024_row [ - log.owning_organisation&.old_visible_id, # 1 - log.managing_organisation&.old_visible_id, + overrides[:organisation_id] || log.owning_organisation&.old_visible_id, # 1 + overrides[:managing_organisation_id] || log.managing_organisation&.old_visible_id, log.assigned_to&.email, log.needstype, log.scheme&.id ? "S#{log.scheme&.id}" : "", @@ -162,10 +164,10 @@ class BulkUpload::LettingsLogToCsv log.propcode, log.declaration, log.uprn, - log.address_line1, - log.address_line2, - log.town_or_city, - log.county, # 20 + log.address_line1&.tr(",", " "), + log.address_line2&.tr(",", " "), + log.town_or_city&.tr(",", " "), + log.county&.tr(",", " "), # 20 ((log.postcode_full || "").split(" ") || [""]).first, ((log.postcode_full || "").split(" ") || [""]).last, diff --git a/spec/support/bulk_upload/sales_log_to_csv.rb b/app/helpers/bulk_upload/sales_log_to_csv.rb similarity index 97% rename from spec/support/bulk_upload/sales_log_to_csv.rb rename to app/helpers/bulk_upload/sales_log_to_csv.rb index 8e2f1be0c..0d37fe344 100644 --- a/spec/support/bulk_upload/sales_log_to_csv.rb +++ b/app/helpers/bulk_upload/sales_log_to_csv.rb @@ -2,10 +2,12 @@ class BulkUpload::SalesLogToCsv attr_reader :log, :line_ending, :col_offset, :overrides def initialize(log:, line_ending: "\n", col_offset: 1, overrides: {}) + # rubocop:disable Rails/HelperInstanceVariable @log = log @line_ending = line_ending @col_offset = col_offset @overrides = overrides + # rubocop:enable Rails/HelperInstanceVariable end def row_prefix @@ -187,7 +189,7 @@ class BulkUpload::SalesLogToCsv log.prevloc, # 40 ((log.ppostcode_full || "").split(" ") || [""]).first, ((log.ppostcode_full || "").split(" ") || [""]).last, - log.ppcodenk == 0 ? 1 : nil, + log.ppcodenk&.zero? ? 1 : nil, log.pregyrha, log.pregla, @@ -311,10 +313,10 @@ class BulkUpload::SalesLogToCsv log.builtype, log.uprn, - log.address_line1, - log.address_line2, - log.town_or_city, - log.county, + log.address_line1&.tr(",", " "), + log.address_line2&.tr(",", " "), + log.town_or_city&.tr(",", " "), + log.county&.tr(",", " "), ((log.postcode_full || "").split(" ") || [""]).first, ((log.postcode_full || "").split(" ") || [""]).last, log.la, diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb index 398f897cf..3ecea6d25 100644 --- a/app/helpers/tag_helper.rb +++ b/app/helpers/tag_helper.rb @@ -21,6 +21,7 @@ module TagHelper processing: "Processing", blank_template: "Blank template", wrong_template: "Wrong template used", + processing_error: "Error processing CSV", important_errors: "Errors on important questions in CSV", critical_errors: "Critical errors in CSV", potential_errors: "Potential errors in CSV", @@ -48,6 +49,7 @@ module TagHelper processing: "yellow", blank_template: "red", wrong_template: "red", + processing_error: "red", important_errors: "red", critical_errors: "red", potential_errors: "red", diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index 2e0232dfe..6616285b0 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -1,7 +1,7 @@ class BulkUpload < ApplicationRecord enum :log_type, { lettings: "lettings", sales: "sales" } enum :rent_type_fix_status, { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" } - enum :failure_reason, { blank_template: "blank_template", wrong_template: "wrong_template" } + enum :failure_reason, { blank_template: "blank_template", wrong_template: "wrong_template", processing_error: "processing_error" } belongs_to :user @@ -43,6 +43,7 @@ class BulkUpload < ApplicationRecord return :processing if processing return :blank_template if failure_reason == "blank_template" return :wrong_template if failure_reason == "wrong_template" + return :processing_error if failure_reason == "processing_error" if logs.visible.exists? return :errors_fixed_in_service if completed? && bulk_upload_errors.any? @@ -129,6 +130,7 @@ class BulkUpload < ApplicationRecord def unpend_and_confirm_soft_validations logs.find_each do |log| fields_to_confirm(log).each { |field| log[field] = 0 } + log.status = log.status_cache log.save! end end diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index ced530b17..6d50bb5ff 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -346,7 +346,7 @@ private end def address_answered_without_uprn? - [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023 + [address_line1, town_or_city].all?(&:present?) && uprn.nil? end def get_lar diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb index df151bd01..c79156d86 100644 --- a/app/models/derived_variables/sales_log_variables.rb +++ b/app/models/derived_variables/sales_log_variables.rb @@ -234,7 +234,7 @@ private end def address_answered_without_uprn? - [address_line1, town_or_city].all?(&:present?) && uprn.nil? && form.start_date.year >= 2023 + [address_line1, town_or_city].all?(&:present?) && uprn.nil? end def soctenant_from_prevten_values diff --git a/app/models/form/lettings/pages/person_lead_partner.rb b/app/models/form/lettings/pages/person_lead_partner.rb new file mode 100644 index 000000000..30613d976 --- /dev/null +++ b/app/models/form/lettings/pages/person_lead_partner.rb @@ -0,0 +1,12 @@ +class Form::Lettings::Pages::PersonLeadPartner < ::Form::Page + def initialize(id, hsh, subsection, person_index:) + super(id, hsh, subsection) + @id = "person_#{person_index}_lead_partner" + @depends_on = [{ "details_known_#{person_index}" => 0 }] + @person_index = person_index + end + + def questions + @questions ||= [Form::Lettings::Questions::PersonPartner.new(nil, nil, self, person_index: @person_index)] + end +end diff --git a/app/models/form/lettings/pages/rent_4_weekly.rb b/app/models/form/lettings/pages/rent_4_weekly.rb index aa6441f6e..4bfaf28ff 100644 --- a/app/models/form/lettings/pages/rent_4_weekly.rb +++ b/app/models/form/lettings/pages/rent_4_weekly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page super @id = "rent_4_weekly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, - { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page Form::Lettings::Questions::Tcharge4Weekly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true }, + { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true }, + ] + else + [ + { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, + { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/pages/rent_bi_weekly.rb b/app/models/form/lettings/pages/rent_bi_weekly.rb index 7eab8daf4..aad9e9312 100644 --- a/app/models/form/lettings/pages/rent_bi_weekly.rb +++ b/app/models/form/lettings/pages/rent_bi_weekly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page super @id = "rent_bi_weekly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, - { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page Form::Lettings::Questions::TchargeBiWeekly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true }, + { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true }, + ] + else + [ + { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, + { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/pages/rent_monthly.rb b/app/models/form/lettings/pages/rent_monthly.rb index 9a3cd6a7e..1fcc21b17 100644 --- a/app/models/form/lettings/pages/rent_monthly.rb +++ b/app/models/form/lettings/pages/rent_monthly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page super @id = "rent_monthly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, - { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page Form::Lettings::Questions::TchargeMonthly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true }, + { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true }, + ] + else + [ + { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, + { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/pages/rent_weekly.rb b/app/models/form/lettings/pages/rent_weekly.rb index 86106cfe3..b40641ebe 100644 --- a/app/models/form/lettings/pages/rent_weekly.rb +++ b/app/models/form/lettings/pages/rent_weekly.rb @@ -3,10 +3,7 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page super @id = "rent_weekly" @copy_key = "lettings.income_and_benefits.rent_and_charges" - @depends_on = [ - { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false }, - { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false }, - ] + @depends_on = depends_on end def questions @@ -18,4 +15,18 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page Form::Lettings::Questions::TchargeWeekly.new(nil, nil, self), ] end + + def depends_on + if form.start_year_2025_or_later? + [ + { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0 }, + { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil }, + ] + else + [ + { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false }, + { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false }, + ] + end + end end diff --git a/app/models/form/lettings/questions/person_partner.rb b/app/models/form/lettings/questions/person_partner.rb new file mode 100644 index 000000000..25c2d72c1 --- /dev/null +++ b/app/models/form/lettings/questions/person_partner.rb @@ -0,0 +1,30 @@ +class Form::Lettings::Questions::PersonPartner < ::Form::Question + def initialize(id, hsh, page, person_index:) + super(id, hsh, page) + @id = "relat#{person_index}" + @type = "radio" + @check_answers_card_number = person_index + @answer_options = answer_options + @person_index = person_index + @question_number = question_number + end + + def answer_options + { + "P" => { "value" => "Yes" }, + "X" => { "value" => "No" }, + "R" => { "value" => "Tenant prefers not to say" }, + } + end + + def question_number + base_question_number = case form.start_date.year + when 2023 + 30 + else + 29 + end + + base_question_number + (4 * @person_index) + end +end diff --git a/app/models/form/lettings/subsections/household_characteristics.rb b/app/models/form/lettings/subsections/household_characteristics.rb index 61334d84c..a454ffed5 100644 --- a/app/models/form/lettings/subsections/household_characteristics.rb +++ b/app/models/form/lettings/subsections/household_characteristics.rb @@ -32,7 +32,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck.new("working_situation_lead_tenant_under_retirement_value_check", nil, self), Form::Lettings::Pages::LeadTenantOverRetirementValueCheck.new("working_situation_lead_tenant_over_retirement_value_check", nil, self), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 2), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 2), + relationship_question(person_index: 2), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_2_multiple_partners_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2), @@ -52,7 +52,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_2_under_retirement_value_check", nil, self, person_index: 2), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_2_over_retirement_value_check", nil, self, person_index: 2), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 3), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 3), + relationship_question(person_index: 3), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_3_multiple_partners_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3), @@ -72,7 +72,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_3_under_retirement_value_check", nil, self, person_index: 3), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_3_over_retirement_value_check", nil, self, person_index: 3), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 4), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 4), + relationship_question(person_index: 4), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_4_multiple_partners_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4), @@ -92,7 +92,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_4_under_retirement_value_check", nil, self, person_index: 4), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_4_over_retirement_value_check", nil, self, person_index: 4), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 5), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 5), + relationship_question(person_index: 5), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_5_multiple_partners_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5), @@ -112,7 +112,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_5_under_retirement_value_check", nil, self, person_index: 5), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_5_over_retirement_value_check", nil, self, person_index: 5), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 6), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 6), + relationship_question(person_index: 6), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_6_multiple_partners_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6), @@ -132,7 +132,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_6_under_retirement_value_check", nil, self, person_index: 6), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_6_over_retirement_value_check", nil, self, person_index: 6), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 7), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 7), + relationship_question(person_index: 7), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_7_multiple_partners_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7), @@ -152,7 +152,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_7_under_retirement_value_check", nil, self, person_index: 7), Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_7_over_retirement_value_check", nil, self, person_index: 7), Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 8), - Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index: 8), + relationship_question(person_index: 8), (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?), (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_8_multiple_partners_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?), Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8), @@ -173,4 +173,12 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_8_over_retirement_value_check", nil, self, person_index: 8), ].compact end + + def relationship_question(person_index:) + if form.start_year_2025_or_later? + Form::Lettings::Pages::PersonLeadPartner.new(nil, nil, self, person_index:) + else + Form::Lettings::Pages::PersonRelationshipToLead.new(nil, nil, self, person_index:) + end + end end diff --git a/app/models/form/lettings/subsections/income_and_benefits.rb b/app/models/form/lettings/subsections/income_and_benefits.rb index 2be2fb9a5..4ad3003cb 100644 --- a/app/models/form/lettings/subsections/income_and_benefits.rb +++ b/app/models/form/lettings/subsections/income_and_benefits.rb @@ -15,11 +15,7 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection Form::Lettings::Pages::BenefitsProportion.new("benefits_proportion", nil, self), Form::Lettings::Pages::RentOrOtherCharges.new(nil, nil, self), Form::Lettings::Pages::RentPeriod.new(nil, nil, self), - Form::Lettings::Pages::CareHomeWeekly.new(nil, nil, self), - Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self), - Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self), - Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self), - Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self), + carehome_questions, Form::Lettings::Pages::RentWeekly.new(nil, nil, self), Form::Lettings::Pages::RentBiWeekly.new(nil, nil, self), Form::Lettings::Pages::Rent4Weekly.new(nil, nil, self), @@ -30,6 +26,20 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection Form::Lettings::Pages::SupchargValueCheck.new(nil, nil, self), Form::Lettings::Pages::Outstanding.new(nil, nil, self), Form::Lettings::Pages::OutstandingAmount.new(nil, nil, self), - ].compact + ].flatten.compact + end + +private + + def carehome_questions + return [] if form.start_year_2025_or_later? + + [ + Form::Lettings::Pages::CareHomeWeekly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self), + Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self), + ] end end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 05eec89dd..a91187003 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -276,7 +276,7 @@ class Form::Question end def question_number_string(hidden: false) - if @question_number && !hidden && form.start_date.year >= 2023 + if @question_number && !hidden "Q#{@question_number}" end end diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 02f3a9d70..9a10dc894 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -36,6 +36,10 @@ class FormHandler forms["next_lettings"] end + def archived_lettings_form + forms["archived_lettings"] + end + def current_sales_form forms["current_sales"] end @@ -44,6 +48,10 @@ class FormHandler forms["previous_sales"] end + def archived_sales_form + forms["archived_sales"] + end + def next_sales_form forms["next_sales"] end diff --git a/app/models/forms/bulk_upload_lettings/checking_file.rb b/app/models/forms/bulk_upload_form/checking_file.rb similarity index 66% rename from app/models/forms/bulk_upload_lettings/checking_file.rb rename to app/models/forms/bulk_upload_form/checking_file.rb index 2ce12df46..6efecc008 100644 --- a/app/models/forms/bulk_upload_lettings/checking_file.rb +++ b/app/models/forms/bulk_upload_form/checking_file.rb @@ -1,22 +1,23 @@ module Forms - module BulkUploadLettings + module BulkUploadForm class CheckingFile include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :year, :integer attribute :organisation_id, :integer def view_path - "bulk_upload_lettings_logs/forms/checking_file" + "bulk_upload_#{log_type}_logs/forms/checking_file" end def back_path if organisation_id.present? - lettings_logs_organisation_path(organisation_id) + send("#{log_type}_logs_organisation_path", organisation_id) else - bulk_upload_lettings_log_path(id: "start") + send("bulk_upload_#{log_type}_log_path", id: "start") end end diff --git a/app/models/forms/bulk_upload_lettings/guidance.rb b/app/models/forms/bulk_upload_form/guidance.rb similarity index 61% rename from app/models/forms/bulk_upload_lettings/guidance.rb rename to app/models/forms/bulk_upload_form/guidance.rb index b2fcf947e..4b62caa21 100644 --- a/app/models/forms/bulk_upload_lettings/guidance.rb +++ b/app/models/forms/bulk_upload_form/guidance.rb @@ -1,11 +1,12 @@ module Forms - module BulkUploadLettings + module BulkUploadForm class Guidance include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers include CollectionTimeHelper + attribute :log_type attribute :year, :integer attribute :referrer attribute :organisation_id, :integer @@ -23,7 +24,7 @@ module Forms def back_path case referrer when "prepare-your-file" - bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) + send("bulk_upload_#{log_type}_log_path", id: "prepare-your-file", form: { year:, organisation_id: }.compact) when "home" root_path else @@ -32,19 +33,19 @@ module Forms end def lettings_template_path - Forms::BulkUploadLettings::PrepareYourFile.new(year:).template_path + Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "lettings").template_path end def lettings_specification_path - Forms::BulkUploadLettings::PrepareYourFile.new(year:).specification_path + Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "lettings").specification_path end def sales_template_path - Forms::BulkUploadSales::PrepareYourFile.new(year:).template_path + Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "sales").template_path end def sales_specification_path - Forms::BulkUploadSales::PrepareYourFile.new(year:).specification_path + Forms::BulkUploadForm::PrepareYourFile.new(year:, log_type: "sales").specification_path end end end diff --git a/app/models/forms/bulk_upload_sales/prepare_your_file.rb b/app/models/forms/bulk_upload_form/prepare_your_file.rb similarity index 57% rename from app/models/forms/bulk_upload_sales/prepare_your_file.rb rename to app/models/forms/bulk_upload_form/prepare_your_file.rb index aaca752a2..911daa4fe 100644 --- a/app/models/forms/bulk_upload_sales/prepare_your_file.rb +++ b/app/models/forms/bulk_upload_form/prepare_your_file.rb @@ -1,42 +1,41 @@ module Forms - module BulkUploadSales + module BulkUploadForm class PrepareYourFile include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :year, :integer attribute :organisation_id, :integer def view_path case year - when 2023 - "bulk_upload_sales_logs/forms/prepare_your_file_2023" when 2024 - "bulk_upload_sales_logs/forms/prepare_your_file_2024" + "bulk_upload_#{log_type}_logs/forms/prepare_your_file_2024" end end def back_path if have_choice_of_year? - Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: }.compact) + Rails.application.routes.url_helpers.send("bulk_upload_#{log_type}_log_path", id: "year", form: { year: }.compact) elsif organisation_id.present? - sales_logs_organisation_path(organisation_id) + send("#{log_type}_logs_organisation_path", organisation_id) else - Rails.application.routes.url_helpers.sales_logs_path + Rails.application.routes.url_helpers.send("#{log_type}_logs_path") end end def next_path - bulk_upload_sales_log_path(id: "upload-your-file", form: { year:, organisation_id: }.compact) + send("bulk_upload_#{log_type}_log_path", id: "upload-your-file", form: { year:, organisation_id: }.compact) end def template_path - download_mandatory_collection_resource_path(year:, log_type: "sales", resource_type: "bulk_upload_template") + download_mandatory_collection_resource_path(year:, log_type:, resource_type: "bulk_upload_template") end def specification_path - download_mandatory_collection_resource_path(year:, log_type: "sales", resource_type: "bulk_upload_specification") + download_mandatory_collection_resource_path(year:, log_type:, resource_type: "bulk_upload_specification") end def year_combo @@ -52,7 +51,7 @@ module Forms def have_choice_of_year? return true if FeatureToggle.allow_future_form_use? - FormHandler.instance.sales_in_crossover_period? + FormHandler.instance.send("#{log_type}_in_crossover_period?") end end end diff --git a/app/models/forms/bulk_upload_lettings/upload_your_file.rb b/app/models/forms/bulk_upload_form/upload_your_file.rb similarity index 82% rename from app/models/forms/bulk_upload_lettings/upload_your_file.rb rename to app/models/forms/bulk_upload_form/upload_your_file.rb index 552710885..3207b1822 100644 --- a/app/models/forms/bulk_upload_lettings/upload_your_file.rb +++ b/app/models/forms/bulk_upload_form/upload_your_file.rb @@ -1,14 +1,14 @@ require "shellwords" module Forms - module BulkUploadLettings + module BulkUploadForm class UploadYourFile include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :year, :integer - attribute :needstype, :integer attribute :file attribute :current_user attribute :organisation_id, :integer @@ -18,11 +18,11 @@ module Forms validate :validate_file_size def view_path - "bulk_upload_lettings_logs/forms/upload_your_file" + "bulk_upload_#{log_type}_logs/forms/upload_your_file" end def back_path - bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, needstype:, organisation_id: }.compact) + send("bulk_upload_#{log_type}_log_path", id: "prepare-your-file", form: { year:, organisation_id: }.compact) end def year_combo @@ -30,15 +30,14 @@ module Forms end def next_path - bulk_upload_lettings_log_path(id: "checking-file", form: { year:, organisation_id: }.compact) + send("bulk_upload_#{log_type}_log_path", id: "checking-file", form: { year:, organisation_id: }.compact) end def save! bulk_upload = BulkUpload.create!( user: current_user, - log_type: BulkUpload.log_types[:lettings], + log_type: BulkUpload.log_types[log_type.to_sym], year:, - needstype:, filename: file.original_filename, organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id, ) diff --git a/app/models/forms/bulk_upload_lettings/year.rb b/app/models/forms/bulk_upload_form/year.rb similarity index 50% rename from app/models/forms/bulk_upload_lettings/year.rb rename to app/models/forms/bulk_upload_form/year.rb index ca2e9c144..ecc3acb5b 100644 --- a/app/models/forms/bulk_upload_lettings/year.rb +++ b/app/models/forms/bulk_upload_form/year.rb @@ -1,17 +1,18 @@ module Forms - module BulkUploadLettings + module BulkUploadForm class Year include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :year, :integer attribute :organisation_id, :integer validates :year, presence: true def view_path - "bulk_upload_lettings_logs/forms/year" + "bulk_upload_#{log_type}_logs/forms/year" end def options @@ -22,14 +23,14 @@ module Forms def back_path if organisation_id.present? - lettings_logs_organisation_path(organisation_id) + send("#{log_type}_logs_organisation_path", organisation_id) else - lettings_logs_path + send("#{log_type}_logs_path") end end def next_path - bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) + send("bulk_upload_#{log_type}_log_path", id: "prepare-your-file", form: { year:, organisation_id: }.compact) end def save! @@ -40,9 +41,9 @@ module Forms def possible_years [ - FormHandler.instance.lettings_forms["current_lettings"].start_date.year, - (FormHandler.instance.previous_lettings_form.start_date.year if FormHandler.instance.lettings_in_crossover_period?), - (FormHandler.instance.next_lettings_form.start_date.year if FeatureToggle.allow_future_form_use?), + FormHandler.instance.send("#{log_type}_forms")["current_#{log_type}"].start_date.year, + (FormHandler.instance.send("previous_#{log_type}_form").start_date.year if FormHandler.instance.send("#{log_type}_in_crossover_period?")), + (FormHandler.instance.send("next_#{log_type}_form").start_date.year if FeatureToggle.allow_future_form_use?), ].compact end end diff --git a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb b/app/models/forms/bulk_upload_lettings/prepare_your_file.rb deleted file mode 100644 index d0a577ee1..000000000 --- a/app/models/forms/bulk_upload_lettings/prepare_your_file.rb +++ /dev/null @@ -1,60 +0,0 @@ -module Forms - module BulkUploadLettings - class PrepareYourFile - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :year, :integer - attribute :needstype, :integer - attribute :organisation_id, :integer - - def view_path - case year - when 2023 - "bulk_upload_lettings_logs/forms/prepare_your_file_2023" - when 2024 - "bulk_upload_lettings_logs/forms/prepare_your_file_2024" - end - end - - def back_path - if have_choice_of_year? - Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year:, organisation_id: }.compact) - elsif organisation_id.present? - lettings_logs_organisation_path(organisation_id) - else - Rails.application.routes.url_helpers.lettings_logs_path - end - end - - def next_path - bulk_upload_lettings_log_path(id: "upload-your-file", form: { year:, needstype:, organisation_id: }.compact) - end - - def template_path - download_mandatory_collection_resource_path(year:, log_type: "lettings", resource_type: "bulk_upload_template") - end - - def specification_path - download_mandatory_collection_resource_path(year:, log_type: "lettings", resource_type: "bulk_upload_specification") - end - - def year_combo - "#{year} to #{year + 1}" - end - - def save! - true - end - - private - - def have_choice_of_year? - return true if FeatureToggle.allow_future_form_use? - - FormHandler.instance.lettings_in_crossover_period? - end - end - end -end diff --git a/app/models/forms/bulk_upload_lettings_resume/confirm.rb b/app/models/forms/bulk_upload_lettings_resume/confirm.rb deleted file mode 100644 index 3419e794f..000000000 --- a/app/models/forms/bulk_upload_lettings_resume/confirm.rb +++ /dev/null @@ -1,55 +0,0 @@ -module Forms - module BulkUploadLettingsResume - class Confirm - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - - def view_path - "bulk_upload_lettings_resume/confirm" - end - - def back_path - page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice") - end - - def next_path - resume_bulk_upload_lettings_result_path(bulk_upload) - end - - def error_report_path - if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - summary_bulk_upload_lettings_result_path(bulk_upload) - else - bulk_upload_lettings_result_path(bulk_upload) - end - end - - def save! - ApplicationRecord.transaction do - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve - - bulk_upload.update!(choice: "create-fix-inline") - end - - true - end - - def preflight_valid? - bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" - end - - def preflight_redirect - case bulk_upload.choice - when "create-fix-inline" - page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) - when "bulk-confirm-soft-validations" - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) - end - end - end - end -end diff --git a/app/models/forms/bulk_upload_lettings_resume/deletion_report.rb b/app/models/forms/bulk_upload_lettings_resume/deletion_report.rb deleted file mode 100644 index 61e7c54cd..000000000 --- a/app/models/forms/bulk_upload_lettings_resume/deletion_report.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Forms - module BulkUploadLettingsResume - class DeletionReport - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - - def view_path - "bulk_upload_lettings_resume/deletion_report" - end - - def preflight_valid? - bulk_upload.choice != "create-fix-inline" && bulk_upload.choice != "bulk-confirm-soft-validations" - end - - def preflight_redirect - case bulk_upload.choice - when "create-fix-inline" - page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) - when "bulk-confirm-soft-validations" - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) - end - end - end - end -end diff --git a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb b/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb deleted file mode 100644 index 40ada602e..000000000 --- a/app/models/forms/bulk_upload_lettings_resume/fix_choice.rb +++ /dev/null @@ -1,74 +0,0 @@ -module Forms - module BulkUploadLettingsResume - class FixChoice - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - attribute :choice, :string - - validates :choice, presence: true, - inclusion: { in: %w[create-fix-inline upload-again] } - - def options - [ - OpenStruct.new(id: "create-fix-inline", name: "Upload these logs and fix errors on CORE site"), - OpenStruct.new(id: "upload-again", name: "Fix errors in the CSV and upload the file again"), - ] - end - - def view_path - "bulk_upload_lettings_resume/fix_choice" - end - - def next_path - case choice - when "create-fix-inline" - page_bulk_upload_lettings_resume_path(bulk_upload, page: "confirm") - when "upload-again" - error_report_path - else - raise "invalid choice" - end - end - - def error_report_path - if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - summary_bulk_upload_lettings_result_path(bulk_upload) - else - bulk_upload_lettings_result_path(bulk_upload) - end - end - - def recommendation - if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - "We recommend fixing these errors in the CSV, as you may be able to edit multiple fields at once. However, you can also upload these logs and fix the errors on the CORE site." - else - "We recommend uploading logs and fixing errors on site as you can easily see the questions and select the appropriate answer. However, you can also fix these errors in the CSV." - end - end - - def save! - bulk_upload.update!(choice:) if choice == "upload-again" - - true - end - - def preflight_valid? - bulk_upload.choice.blank? - end - - def preflight_redirect - case bulk_upload.choice - when "create-fix-inline" - page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) - when "bulk-confirm-soft-validations" - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) - else - bulk_upload_lettings_result_path(bulk_upload) - end - end - end - end -end diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb deleted file mode 100644 index b3091bc51..000000000 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/chosen.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Forms - module BulkUploadLettingsSoftValidationsCheck - class Chosen - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - - def view_path - "bulk_upload_lettings_soft_validations_check/chosen" - end - - def back_path - lettings_logs_path - end - - def next_path - lettings_logs_path - end - - def save! - true - end - - def preflight_valid? - true - end - end - end -end diff --git a/app/models/forms/bulk_upload_lettings_resume/chosen.rb b/app/models/forms/bulk_upload_resume/chosen.rb similarity index 60% rename from app/models/forms/bulk_upload_lettings_resume/chosen.rb rename to app/models/forms/bulk_upload_resume/chosen.rb index b795d8d4b..935d29178 100644 --- a/app/models/forms/bulk_upload_lettings_resume/chosen.rb +++ b/app/models/forms/bulk_upload_resume/chosen.rb @@ -1,22 +1,23 @@ module Forms - module BulkUploadLettingsResume + module BulkUploadResume class Chosen include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload def view_path - bulk_upload.completed? ? "bulk_upload_lettings_resume/completed" : "bulk_upload_lettings_resume/chosen" + bulk_upload.completed? ? "bulk_upload_#{log_type}_resume/completed" : "bulk_upload_#{log_type}_resume/chosen" end def back_path - lettings_logs_path + send("#{log_type}_logs_path") end def next_path - lettings_logs_path + send("#{log_type}_logs_path") end def save! diff --git a/app/models/forms/bulk_upload_sales_resume/confirm.rb b/app/models/forms/bulk_upload_resume/confirm.rb similarity index 62% rename from app/models/forms/bulk_upload_sales_resume/confirm.rb rename to app/models/forms/bulk_upload_resume/confirm.rb index a84272682..96a1fe1bc 100644 --- a/app/models/forms/bulk_upload_sales_resume/confirm.rb +++ b/app/models/forms/bulk_upload_resume/confirm.rb @@ -1,29 +1,30 @@ module Forms - module BulkUploadSalesResume + module BulkUploadResume class Confirm include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload def view_path - "bulk_upload_sales_resume/confirm" + "bulk_upload_#{log_type}_resume/confirm" end def back_path - page_bulk_upload_sales_resume_path(bulk_upload, page: "fix-choice") + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, page: "fix-choice") end def next_path - resume_bulk_upload_sales_result_path(bulk_upload) + send("resume_bulk_upload_#{log_type}_result_path", bulk_upload) end def error_report_path if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - summary_bulk_upload_sales_result_path(bulk_upload) + send("summary_bulk_upload_#{log_type}_result_path", bulk_upload) else - bulk_upload_sales_result_path(bulk_upload) + send("bulk_upload_#{log_type}_result_path", bulk_upload) end end @@ -45,9 +46,9 @@ module Forms def preflight_redirect case bulk_upload.choice when "create-fix-inline" - page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen) when "bulk-confirm-soft-validations" - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen) end end end diff --git a/app/models/forms/bulk_upload_sales_resume/deletion_report.rb b/app/models/forms/bulk_upload_resume/deletion_report.rb similarity index 65% rename from app/models/forms/bulk_upload_sales_resume/deletion_report.rb rename to app/models/forms/bulk_upload_resume/deletion_report.rb index 93b466b51..40c532553 100644 --- a/app/models/forms/bulk_upload_sales_resume/deletion_report.rb +++ b/app/models/forms/bulk_upload_resume/deletion_report.rb @@ -1,14 +1,15 @@ module Forms - module BulkUploadSalesResume + module BulkUploadResume class DeletionReport include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload def view_path - "bulk_upload_sales_resume/deletion_report" + "bulk_upload_#{log_type}_resume/deletion_report" end def preflight_valid? @@ -18,9 +19,9 @@ module Forms def preflight_redirect case bulk_upload.choice when "create-fix-inline" - page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen) when "bulk-confirm-soft-validations" - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen) end end end diff --git a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb b/app/models/forms/bulk_upload_resume/fix_choice.rb similarity index 76% rename from app/models/forms/bulk_upload_sales_resume/fix_choice.rb rename to app/models/forms/bulk_upload_resume/fix_choice.rb index 79d06529a..c731dbf93 100644 --- a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb +++ b/app/models/forms/bulk_upload_resume/fix_choice.rb @@ -1,10 +1,11 @@ module Forms - module BulkUploadSalesResume + module BulkUploadResume class FixChoice include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload attribute :choice, :string @@ -19,13 +20,13 @@ module Forms end def view_path - "bulk_upload_sales_resume/fix_choice" + "bulk_upload_#{log_type}_resume/fix_choice" end def next_path case choice when "create-fix-inline" - page_bulk_upload_sales_resume_path(bulk_upload, page: "confirm") + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, page: "confirm") when "upload-again" error_report_path else @@ -35,9 +36,9 @@ module Forms def error_report_path if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - summary_bulk_upload_sales_result_path(bulk_upload) + send("summary_bulk_upload_#{log_type}_result_path", bulk_upload) else - bulk_upload_sales_result_path(bulk_upload) + send("bulk_upload_#{log_type}_result_path", bulk_upload) end end @@ -62,11 +63,11 @@ module Forms def preflight_redirect case bulk_upload.choice when "create-fix-inline" - page_bulk_upload_sales_resume_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen) when "bulk-confirm-soft-validations" - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen) else - bulk_upload_sales_result_path(bulk_upload) + send("bulk_upload_#{log_type}_result_path", bulk_upload) end end end diff --git a/app/models/forms/bulk_upload_sales/checking_file.rb b/app/models/forms/bulk_upload_sales/checking_file.rb deleted file mode 100644 index 4e512b29b..000000000 --- a/app/models/forms/bulk_upload_sales/checking_file.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Forms - module BulkUploadSales - class CheckingFile - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :year, :integer - attribute :organisation_id, :integer - - def view_path - "bulk_upload_sales_logs/forms/checking_file" - end - - def back_path - if organisation_id.present? - sales_logs_organisation_path(organisation_id) - else - bulk_upload_sales_log_path(id: "start") - end - end - - def year_combo - "#{year} to #{year + 1}" - end - - def save! - true - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales/guidance.rb b/app/models/forms/bulk_upload_sales/guidance.rb deleted file mode 100644 index 80cfc5143..000000000 --- a/app/models/forms/bulk_upload_sales/guidance.rb +++ /dev/null @@ -1,51 +0,0 @@ -module Forms - module BulkUploadSales - class Guidance - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - include CollectionTimeHelper - - attribute :year, :integer - attribute :referrer - attribute :organisation_id, :integer - - def initialize(params) - super(params) - - self.year = current_collection_start_year if year.nil? - end - - def view_path - "bulk_upload_shared/guidance" - end - - def back_path - case referrer - when "prepare-your-file" - bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) - when "home" - root_path - else - guidance_path - end - end - - def lettings_template_path - Forms::BulkUploadLettings::PrepareYourFile.new(year:).template_path - end - - def lettings_specification_path - Forms::BulkUploadLettings::PrepareYourFile.new(year:).specification_path - end - - def sales_template_path - Forms::BulkUploadSales::PrepareYourFile.new(year:).template_path - end - - def sales_specification_path - Forms::BulkUploadSales::PrepareYourFile.new(year:).specification_path - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales/upload_your_file.rb b/app/models/forms/bulk_upload_sales/upload_your_file.rb deleted file mode 100644 index 447574d1a..000000000 --- a/app/models/forms/bulk_upload_sales/upload_your_file.rb +++ /dev/null @@ -1,83 +0,0 @@ -require "shellwords" - -module Forms - module BulkUploadSales - class UploadYourFile - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :year, :integer - attribute :file - attribute :current_user - attribute :organisation_id, :integer - - validates :file, presence: true - validate :validate_file_is_csv - validate :validate_file_size - - def view_path - "bulk_upload_sales_logs/forms/upload_your_file" - end - - def back_path - bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) - end - - def year_combo - "#{year} to #{year + 1}" - end - - def next_path - bulk_upload_sales_log_path(id: "checking-file", form: { year:, organisation_id: }.compact) - end - - def save! - bulk_upload = BulkUpload.create!( - user: current_user, - log_type: BulkUpload.log_types[:sales], - year:, - filename: file.original_filename, - organisation_id: (organisation_id if current_user.support?) || current_user.organisation_id, - ) - - storage_service.write_file(bulk_upload.identifier, File.read(file.path)) - - ProcessBulkUploadJob.perform_later(bulk_upload:) - - true - end - - private - - def storage_service - @storage_service ||= if FeatureToggle.upload_enabled? - Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"]) - else - Storage::LocalDiskService.new - end - end - - def validate_file_is_csv - return unless file - - argv = %W[file --brief --mime-type -- #{file.path}] - output = `#{argv.shelljoin}` - - unless output.match?(/text\/csv|text\/plain/) - errors.add(:file, :not_csv) - end - end - - MAX_FILE_SIZE = 10.megabytes - - def validate_file_size - return unless file - - if file.size > MAX_FILE_SIZE - errors.add(:file, :file_too_large) - end - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales/year.rb b/app/models/forms/bulk_upload_sales/year.rb deleted file mode 100644 index ecf74c636..000000000 --- a/app/models/forms/bulk_upload_sales/year.rb +++ /dev/null @@ -1,50 +0,0 @@ -module Forms - module BulkUploadSales - class Year - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :year, :integer - attribute :organisation_id, :integer - - validates :year, presence: true - - def view_path - "bulk_upload_sales_logs/forms/year" - end - - def options - possible_years.map do |year| - OpenStruct.new(id: year, name: "#{year} to #{year + 1}") - end - end - - def back_path - if organisation_id.present? - sales_logs_organisation_path(organisation_id) - else - sales_logs_path - end - end - - def next_path - bulk_upload_sales_log_path(id: "prepare-your-file", form: { year:, organisation_id: }.compact) - end - - def save! - true - end - - private - - def possible_years - [ - FormHandler.instance.current_sales_form.start_date.year, - (FormHandler.instance.previous_sales_form.start_date.year if FormHandler.instance.sales_in_crossover_period?), - (FormHandler.instance.next_sales_form.start_date.year if FeatureToggle.allow_future_form_use?), - ].compact - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb deleted file mode 100644 index 2286d3b39..000000000 --- a/app/models/forms/bulk_upload_sales_soft_validations_check/chosen.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Forms - module BulkUploadSalesSoftValidationsCheck - class Chosen - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - - def view_path - "bulk_upload_sales_soft_validations_check/chosen" - end - - def back_path - sales_logs_path - end - - def next_path - sales_logs_path - end - - def save! - true - end - - def preflight_valid? - true - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb deleted file mode 100644 index 894f55123..000000000 --- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm.rb +++ /dev/null @@ -1,47 +0,0 @@ -module Forms - module BulkUploadSalesSoftValidationsCheck - class Confirm - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - - def view_path - "bulk_upload_sales_soft_validations_check/confirm" - end - - def back_path - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, page: "confirm-soft-errors") - end - - def next_path - sales_logs_path - end - - def save! - ApplicationRecord.transaction do - processor = BulkUpload::Processor.new(bulk_upload:) - processor.approve_and_confirm_soft_validations - - bulk_upload.update!(choice: "bulk-confirm-soft-validations") - end - - true - end - - def preflight_valid? - bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" - end - - def preflight_redirect - case bulk_upload.choice - when "bulk-confirm-soft-validations" - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) - when "create-fix-inline" - page_bulk_upload_sales_resume_path(bulk_upload, :chosen) - end - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb b/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb deleted file mode 100644 index 041647cf0..000000000 --- a/app/models/forms/bulk_upload_sales_soft_validations_check/confirm_soft_errors.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Forms - module BulkUploadSalesSoftValidationsCheck - class ConfirmSoftErrors - include ActiveModel::Model - include ActiveModel::Attributes - include Rails.application.routes.url_helpers - - attribute :bulk_upload - attribute :confirm_soft_errors, :string - - validates :confirm_soft_errors, presence: true - - def options - [ - OpenStruct.new(id: "yes", name: "Yes, these fields are correct"), - OpenStruct.new(id: "no", name: "No, there are errors"), - ] - end - - def view_path - "bulk_upload_sales_soft_validations_check/confirm_soft_errors" - end - - def next_path - case confirm_soft_errors - when "no" - page_bulk_upload_sales_resume_path(bulk_upload, page: "fix-choice", soft_errors_only: true) - when "yes" - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, page: "confirm") - else - raise "invalid choice" - end - end - - def save! - true - end - - def preflight_valid? - bulk_upload.choice != "bulk-confirm-soft-validations" && bulk_upload.choice != "create-fix-inline" - end - - def preflight_redirect - case bulk_upload.choice - when "bulk-confirm-soft-validations" - page_bulk_upload_sales_soft_validations_check_path(bulk_upload, :chosen) - when "create-fix-inline" - page_bulk_upload_sales_resume_path(bulk_upload, :chosen) - end - end - end - end -end diff --git a/app/models/forms/bulk_upload_sales_resume/chosen.rb b/app/models/forms/bulk_upload_soft_validations_check/chosen.rb similarity index 65% rename from app/models/forms/bulk_upload_sales_resume/chosen.rb rename to app/models/forms/bulk_upload_soft_validations_check/chosen.rb index 3bf32ee71..359eea9dd 100644 --- a/app/models/forms/bulk_upload_sales_resume/chosen.rb +++ b/app/models/forms/bulk_upload_soft_validations_check/chosen.rb @@ -1,22 +1,23 @@ module Forms - module BulkUploadSalesResume + module BulkUploadSoftValidationsCheck class Chosen include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload def view_path - bulk_upload.completed? ? "bulk_upload_sales_resume/completed" : "bulk_upload_sales_resume/chosen" + "bulk_upload_#{log_type}_soft_validations_check/chosen" end def back_path - sales_logs_path + send("#{log_type}_logs_path") end def next_path - sales_logs_path + send("#{log_type}_logs_path") end def save! diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb b/app/models/forms/bulk_upload_soft_validations_check/confirm.rb similarity index 65% rename from app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb rename to app/models/forms/bulk_upload_soft_validations_check/confirm.rb index aba75791e..8700937cb 100644 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm.rb +++ b/app/models/forms/bulk_upload_soft_validations_check/confirm.rb @@ -1,22 +1,23 @@ module Forms - module BulkUploadLettingsSoftValidationsCheck + module BulkUploadSoftValidationsCheck class Confirm include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload def view_path - "bulk_upload_lettings_soft_validations_check/confirm" + "bulk_upload_#{log_type}_soft_validations_check/confirm" end def back_path - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, page: "confirm-soft-errors") + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, page: "confirm-soft-errors") end def next_path - lettings_logs_path + send("#{log_type}_logs_path") end def save! @@ -37,9 +38,9 @@ module Forms def preflight_redirect case bulk_upload.choice when "bulk-confirm-soft-validations" - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen) when "create-fix-inline" - page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen) end end end diff --git a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb b/app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb similarity index 65% rename from app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb rename to app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb index 34b4b97f3..aeb072152 100644 --- a/app/models/forms/bulk_upload_lettings_soft_validations_check/confirm_soft_errors.rb +++ b/app/models/forms/bulk_upload_soft_validations_check/confirm_soft_errors.rb @@ -1,10 +1,11 @@ module Forms - module BulkUploadLettingsSoftValidationsCheck + module BulkUploadSoftValidationsCheck class ConfirmSoftErrors include ActiveModel::Model include ActiveModel::Attributes include Rails.application.routes.url_helpers + attribute :log_type attribute :bulk_upload attribute :confirm_soft_errors, :string @@ -18,15 +19,15 @@ module Forms end def view_path - "bulk_upload_lettings_soft_validations_check/confirm_soft_errors" + "bulk_upload_#{log_type}_soft_validations_check/confirm_soft_errors" end def next_path case confirm_soft_errors when "no" - page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice", soft_errors_only: true) + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, page: "fix-choice", soft_errors_only: true) when "yes" - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, page: "confirm") + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, page: "confirm") else raise "invalid choice" end @@ -43,9 +44,9 @@ module Forms def preflight_redirect case bulk_upload.choice when "bulk-confirm-soft-validations" - page_bulk_upload_lettings_soft_validations_check_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_soft_validations_check_path", bulk_upload, :chosen) when "create-fix-inline" - page_bulk_upload_lettings_resume_path(bulk_upload, :chosen) + send("page_bulk_upload_#{log_type}_resume_path", bulk_upload, :chosen) end end end diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 67cafb75b..c8505b310 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -240,7 +240,7 @@ class LettingsLog < Log end def applicable_income_range - return unless ecstat1 && hhmemb + return unless ecstat1 && hhmemb && ALLOWED_INCOME_RANGES[ecstat1] range = ALLOWED_INCOME_RANGES[ecstat1].clone @@ -670,8 +670,7 @@ class LettingsLog < Log ["owning_organisation_id", "startdate", "tenancycode", - form.start_date.year < 2023 || uprn.blank? ? "postcode_full" : nil, - form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil, + uprn.blank? ? "postcode_full" : "uprn", "scheme_id", "location_id", "age1", @@ -884,7 +883,6 @@ private def should_process_uprn_change? return unless uprn return unless startdate - return unless collection_start_year_for_date(startdate) >= 2023 uprn_changed? || startdate_changed? end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 3064cba31..49ba9f81c 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -61,13 +61,14 @@ class SalesLog < Log [by_postcode, param_without_spaces, param_without_spaces]) } scope :age1_answered, -> { where.not(age1: nil).or(where(age1_known: [1, 2])) } + scope :ecstat1_answered, -> { where.not(ecstat1: nil).or(where("saledate >= ?", Time.zone.local(2025, 4, 1))) } scope :duplicate_logs, lambda { |log| visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) .where.not(id: log.id) .where.not(saledate: nil) .where.not(sex1: nil) - .where.not(ecstat1: nil) .where.not(postcode_full: nil) + .ecstat1_answered .age1_answered } scope :after_date, ->(date) { where("saledate >= ?", date) } @@ -77,9 +78,9 @@ class SalesLog < Log .group(*DUPLICATE_LOG_ATTRIBUTES) .where.not(saledate: nil) .where.not(sex1: nil) - .where.not(ecstat1: nil) .where.not(postcode_full: nil) .age1_answered + .ecstat1_answered .having("COUNT(*) > 1") if assigned_to_id @@ -128,33 +129,12 @@ class SalesLog < Log def dynamically_not_required not_required = [] - not_required << "proplen" if proplen_optional? - not_required << "mortlen" if mortlen_optional? - not_required << "frombeds" if frombeds_optional? not_required << "deposit" if form.start_year_2024_or_later? && stairowned_100? not_required += %w[address_line2 county] not_required end - def proplen_optional? - return false unless collection_start_year - - collection_start_year < 2023 - end - - def mortlen_optional? - return false unless collection_start_year - - collection_start_year < 2023 - end - - def frombeds_optional? - return false unless collection_start_year - - collection_start_year < 2023 - end - def unresolved false end @@ -439,16 +419,15 @@ class SalesLog < Log def income_soft_min_for_ecstat(ecstat_field) economic_status_code = public_send(ecstat_field) - return unless ALLOWED_INCOME_RANGES_SALES + return unless ALLOWED_INCOME_RANGES_SALES && ALLOWED_INCOME_RANGES_SALES[economic_status_code] - soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code]&.soft_min + soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code].soft_min format_as_currency(soft_min) end def should_process_uprn_change? return unless uprn return unless saledate - return unless collection_start_year_for_date(saledate) >= 2023 uprn_changed? || saledate_changed? end @@ -513,8 +492,7 @@ class SalesLog < Log "age1", "sex1", "ecstat1", - form.start_date.year < 2023 || uprn.blank? ? "postcode_full" : nil, - form.start_date.year >= 2023 && uprn.present? ? "uprn" : nil].compact + uprn.blank? ? "postcode_full" : "uprn"].compact end def soctenant_is_inferred? diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 7462290b6..f69f41cdd 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -2,53 +2,56 @@ module Validations::DateValidations include Validations::SharedValidations def validate_property_major_repairs(record) - date_valid?("mrcdate", record) - if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"] - record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_tenancy_start") - end + return unless record["mrcdate"].present? && date_valid?("mrcdate", record) if is_rsnvac_first_let?(record) && record["mrcdate"].present? record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.not_first_let") end + return unless record["startdate"].present? && date_valid?("startdate", record) - if record["mrcdate"].present? && record["startdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650 + if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"] + record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_tenancy_start") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_major_repair_date") + end + + if record.form.start_year_2025_or_later? + if record["startdate"].to_date - 20.years > record["mrcdate"].to_date + record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.twenty_years_before_tenancy_start") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.twenty_years_after_mrc_date") + end + elsif record["startdate"].to_date - 10.years > record["mrcdate"].to_date record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date") end end def validate_property_void_date(record) - if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 - record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start") - end - - if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date - record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.before_tenancy_start") - end + return unless record["voiddate"].present? && date_valid?("voiddate", record) - if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date + if record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date record.errors.add :voiddate, :after_mrcdate, message: I18n.t("validations.lettings.date.void_date.after_mrcdate") record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_void_date") end - end - - def validate_startdate(record) - return unless record.startdate && date_valid?("startdate", record) + return unless record["startdate"].present? && date_valid?("startdate", record) - if record["voiddate"].present? && record.startdate < record["voiddate"] + if record["startdate"].to_date < record["voiddate"].to_date + record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.before_tenancy_start") record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_void_date") end - if record["mrcdate"].present? && record.startdate < record["mrcdate"] - record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_major_repair_date") - end - - if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 + if record.form.start_year_2025_or_later? + if record["startdate"].to_date - 20.years > record["voiddate"].to_date + record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.twenty_years_before_tenancy_start") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.twenty_years_after_void_date") + end + elsif record["startdate"].to_date - 10.years > record["voiddate"].to_date + record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start") record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_void_date") end + end - if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650 - record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date") - end + def validate_startdate(record) + date_valid?("startdate", record) end private diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 73b389f4c..82b3fae01 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -25,7 +25,7 @@ module Validations::FinancialValidations end def validate_net_income(record) - if record.ecstat1 && record.hhmemb && record.weekly_net_income && record.startdate && record.form.start_date.year >= 2023 + if record.ecstat1 && record.hhmemb && record.weekly_net_income && record.startdate if record.weekly_net_income > record.applicable_income_range.hard_max frequency = record.form.get_question("incfreq", record).label_from_value(record.incfreq).downcase hard_max = format_as_currency(record.applicable_income_range.hard_max) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index cf0ae009e..b4fa934dc 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -201,7 +201,7 @@ module Validations::HouseholdValidations def validate_layear_and_prevloc(record) return unless record.layear && record.la && record.prevloc && record.collection_start_year - if record.la == record.prevloc && record.layear == 1 && record.collection_start_year >= 2023 + if record.la == record.prevloc && record.layear == 1 record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area") record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.lettings.household.la.same_la_just_moved_to_area") record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area") diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index 91d4c31b7..e5d8232f0 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/app/models/validations/sales/financial_validations.rb @@ -82,7 +82,7 @@ module Validations::Sales::FinancialValidations def validate_child_income(record) return unless record.income2 && record.ecstat2 - if record.income2.positive? && is_economic_status_child?(record.ecstat2) && record.form.start_date.year >= 2023 + if record.income2.positive? && is_economic_status_child?(record.ecstat2) record.errors.add :ecstat2, I18n.t("validations.sales.financial.ecstat2.child_has_income") record.errors.add :income2, I18n.t("validations.sales.financial.income2.child_has_income") end diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb index 175474098..e5a66f935 100644 --- a/app/models/validations/sales/household_validations.rb +++ b/app/models/validations/sales/household_validations.rb @@ -13,8 +13,6 @@ module Validations::Sales::HouseholdValidations end def validate_buyers_living_in_property(record) - return unless record.form.start_date.year >= 2023 - if record.buyers_will_live_in? && record.buyer_one_will_not_live_in_property? && record.buyer_two_will_not_live_in_property? record.errors.add :buylivein, I18n.t("validations.sales.household.buylivein.buyers_will_live_in_property_values_inconsistent") record.errors.add :buy1livein, I18n.t("validations.sales.household.buy1livein.buyers_will_live_in_property_values_inconsistent") diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 4b8948053..f99f6668a 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -144,11 +144,11 @@ module Validations::Sales::SaleInformationValidations return unless record.saledate && record.form.start_year_2024_or_later? return unless record.discount && record.value && record.la - if record.london_property? && record.discount_value > 136_400 + if record.london_property? && record.discount_value > 137_400 %i[discount value la postcode_full uprn].each do |field| record.errors.add field, I18n.t("validations.sales.sale_information.#{field}.value_over_discounted_london_max", discount_value: record.field_formatted_as_currency("discount_value")) end - elsif record.property_not_in_london? && record.discount_value > 102_400 + elsif record.property_not_in_london? && record.discount_value > 103_400 %i[discount value la postcode_full uprn].each do |field| record.errors.add field, I18n.t("validations.sales.sale_information.#{field}.value_over_discounted_max", discount_value: record.field_formatted_as_currency("discount_value")) end diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index da79599ee..7b0ecc420 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -54,14 +54,15 @@ module Validations::SharedValidations field = question.check_answer_label || question.id incorrect_accuracy = (value.to_d * 100) % (question.step * 100) != 0 - if question.step < 1 && incorrect_accuracy - record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_hundredth", field:) - elsif incorrect_accuracy || value.to_d != value.to_i # if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value - field = question.check_answer_label || question.id - case question.step - when 1 then record.errors.add question.id.to_sym, :not_integer, message: I18n.t("validations.shared.numeric.whole_number", field:) - when 10 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_ten", field:) - end + next unless incorrect_accuracy + + case question.step + when 0.01 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_hundredth", field:) + when 0.1 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_tenth", field:) + when 1 then record.errors.add question.id.to_sym, :not_integer, message: I18n.t("validations.shared.numeric.whole_number", field:) + when 10 then record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_ten", field:) + else + record.errors.add question.id.to_sym, I18n.t("validations.shared.numeric.nearest_step", field:, step: question.step) end end end diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 1a2c61138..9dc8828e8 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -16,13 +16,13 @@ module Validations::SoftValidations }.freeze def net_income_in_soft_max_range? - return unless weekly_net_income && ecstat1 && hhmemb + return unless weekly_net_income && ecstat1 && hhmemb && applicable_income_range weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max) end def net_income_in_soft_min_range? - return unless weekly_net_income && ecstat1 && hhmemb + return unless weekly_net_income && ecstat1 && hhmemb && applicable_income_range weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min) end diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index c54032fda..f6ce5eaea 100644 --- a/app/services/bulk_upload/processor.rb +++ b/app/services/bulk_upload/processor.rb @@ -61,6 +61,7 @@ class BulkUpload::Processor end rescue StandardError => e Sentry.capture_exception(e) + @bulk_upload.update!(failure_reason: "processing_error") send_failure_mail ensure downloader.delete_local_file! @@ -184,6 +185,8 @@ private @bulk_upload.update!(failure_reason: "blank_template") elsif wrong_template_errors.any? { |error| validator.errors.full_messages.include?(error) } @bulk_upload.update!(failure_reason: "wrong_template") + else + @bulk_upload.update!(failure_reason: "processing_error") end send_failure_mail(errors: validator.errors.full_messages) diff --git a/app/services/documentation_generator.rb b/app/services/documentation_generator.rb index d77a4e093..43426d8d4 100644 --- a/app/services/documentation_generator.rb +++ b/app/services/documentation_generator.rb @@ -18,14 +18,16 @@ class DocumentationGenerator next end - validation_source = method(meth).source + validation = method(meth) + validation_source = validation.source + file_path = validation.source_location[0] helper_methods_source = all_helper_methods.map { |helper_method| if validation_source.include?(helper_method.to_s) method(helper_method).source end }.compact.join("\n") - response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form) + response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form, file_path) next unless response begin @@ -41,19 +43,19 @@ class DocumentationGenerator def describe_bu_validations(client, form, row_parser_class, all_validation_methods, all_helper_methods, field_mapping_for_errors, log_type) all_validation_methods.each do |meth| - if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, from: form.start_date, log_type:).exists? + if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", log_type:).exists? Rails.logger.info("Validation #{meth} already exists for #{form.start_date.year}") next end - - validation_source = row_parser_class.instance_method(meth).source + validation = row_parser_class.instance_method(meth) + validation_source = validation.source helper_methods_source = all_helper_methods.map { |helper_method| if validation_source.include?(helper_method.to_s) row_parser_class.instance_method(helper_method).source end }.compact.join("\n") - response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form) + response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form, validation.source_location[0]) next unless response begin @@ -69,7 +71,7 @@ class DocumentationGenerator def describe_soft_validations(client, all_validation_methods, all_helper_methods, log_type) validation_descriptions = {} - all_validation_methods.each do |meth| + all_validation_methods[0..5].each do |meth| validation_source = method(meth).source helper_methods_source = all_helper_methods.map { |helper_method| if validation_source.include?(helper_method.to_s) @@ -101,8 +103,8 @@ class DocumentationGenerator private - def describe_hard_validation(client, meth, validation_source, helper_methods_source, form) - en_yml = File.read("./config/locales/en.yml") + def describe_hard_validation(client, meth, validation_source, helper_methods_source, form, file_path) + en_yml = File.read(translation_file_path(form, file_path)) begin client.chat( @@ -166,14 +168,6 @@ private required: %w[error_message field], }, }, - from: { - type: :number, - description: "the year from which the validation starts. If this validation runs for logs with a startdate after a certain year, specify that year here, only if it is not specified in the validation method, leave this field blank", - }, - to: { - type: :number, - description: "the year in which the validation ends. If this validation runs for logs with a startdate before a certain year, specify that year here, only if it is not specified in the validation method, leave this field blank", - }, validation_type: { type: :string, enum: %w[presence format minimum maximum range inclusion length other], @@ -271,8 +265,7 @@ Look at these helper methods where needed to understand what is being checked in error_message: error["error_message"], case: case_info["case_description"], section: form.get_question(error["field"], nil)&.subsection&.id, - from: case_info["from"] || "", - to: case_info["to"] || "", + collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", validation_type: case_info["validation_type"], hard_soft: "hard", other_validated_models: case_info["other_validated_models"]) @@ -295,8 +288,7 @@ Look at these helper methods where needed to understand what is being checked in error_message: error["error_message"], case: case_info["case_description"], section: form.get_question(error_field, nil)&.subsection&.id, - from: form.start_date, - to: form.start_date + 1.year, + collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", validation_type: case_info["validation_type"], hard_soft: "hard", other_validated_models: case_info["other_validated_models"], @@ -333,7 +325,7 @@ Look at these helper methods where needed to understand what is being checked in return end - if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, from: form.start_date, log_type:).exists? + if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", log_type:).exists? Rails.logger.info("Validation #{validation_depends_on_hash.keys.first} already exists for #{page_the_validation_applied_to.questions.first.id} for start year #{form.start_date.year}") return end @@ -360,12 +352,30 @@ Look at these helper methods where needed to understand what is being checked in error_message:, case: case_info, section: form.get_question(page_the_validation_applied_to.questions.first.id, nil)&.subsection&.id, - from: form.start_date, - to: form.start_date + 1.year, + collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", validation_type: result["validation_type"], hard_soft: "soft", other_validated_models: result["other_validated_models"]) Rails.logger.info("******** described #{validation_depends_on_hash.keys.first} for #{page_the_validation_applied_to.questions.first.id} ********") end + + TRANSLATION_FILE_MAPPINGS = { + "property" => "property_information", + }.freeze + + def translation_file_path(form, file_path) + return "./config/locales/validations/#{form.type}/#{form.start_date.year}/bulk_upload.en.yml" if file_path.include?("bulk_upload") + + file_name = file_path.split("/").last.gsub("_validations.rb", "") + translation_file_name = TRANSLATION_FILE_MAPPINGS[file_name] || file_name + + file_path = "./config/locales/validations/#{form.type}/#{translation_file_name}.en.yml" + return file_path if File.exist?(file_path) + + shared_file_path = "./config/locales/validations/#{translation_file_name}.en.yml" + return shared_file_path if File.exist?(shared_file_path) + + "./config/locales/en.yml" + end end diff --git a/app/services/exports/organisation_export_constants.rb b/app/services/exports/organisation_export_constants.rb index 3a1c5fb48..6c78a55db 100644 --- a/app/services/exports/organisation_export_constants.rb +++ b/app/services/exports/organisation_export_constants.rb @@ -22,6 +22,7 @@ module Exports::OrganisationExportConstants "dsa_signed_at", "dpo_email", "profit_status", - "group" + "group", + "status" ] end diff --git a/app/services/exports/organisation_export_service.rb b/app/services/exports/organisation_export_service.rb index afcf16cb0..8ceba93a9 100644 --- a/app/services/exports/organisation_export_service.rb +++ b/app/services/exports/organisation_export_service.rb @@ -65,6 +65,8 @@ module Exports attribute_hash["available_from"] = organisation.available_from&.iso8601 attribute_hash["profit_status"] = nil # will need update when we add the field to the org attribute_hash["group"] = nil # will need update when we add the field to the org + attribute_hash["status"] = organisation.status + attribute_hash["active"] = attribute_hash["status"] == :active attribute_hash end diff --git a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb b/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb deleted file mode 100644 index f8549807b..000000000 --- a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb +++ /dev/null @@ -1,46 +0,0 @@ -<% content_for :before_content do %> - <%= govuk_back_link href: @form.back_path %> -<% end %> - -
<%= govuk_link_to "Read the full guidance", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.
- -Use one of these templates to upload logs for 2023/24:
-There are 7 or 8 rows of content in the templates. These rows are called the ‘headers’. They contain the CORE form questions and guidance about which questions are required and how to format your answers.
- -File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_lettings_results/summary.html.erb b/app/views/bulk_upload_lettings_results/summary.html.erb index 2f565ed59..ab60212e9 100644 --- a/app/views/bulk_upload_lettings_results/summary.html.erb +++ b/app/views/bulk_upload_lettings_results/summary.html.erb @@ -6,7 +6,7 @@- We could not create logs from your bulk upload because of the following errors. Download the <%= govuk_link_to "specification", Forms::BulkUploadLettings::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file. + We could not create logs from your bulk upload because of the following errors. Download the <%= govuk_link_to "specification", Forms::BulkUploadForm::PrepareYourFile.new(year: @bulk_upload.year, log_type: "lettings").specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb b/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb deleted file mode 100644 index 427a835e8..000000000 --- a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb +++ /dev/null @@ -1,40 +0,0 @@ -<% content_for :before_content do %> - <%= govuk_back_link href: @form.back_path %> -<% end %> - -<%= govuk_link_to "Read the full guidance", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.
- -Use one of these templates to upload logs for 2023/24:
-There are 7 or 8 rows of content in the templates. These rows are called the ‘headers’. They contain the CORE form questions and guidance about which questions are required and how to format your answers.
- -File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_sales_results/summary.html.erb b/app/views/bulk_upload_sales_results/summary.html.erb index 2ae2a915b..ed2ec14b3 100644 --- a/app/views/bulk_upload_sales_results/summary.html.erb +++ b/app/views/bulk_upload_sales_results/summary.html.erb @@ -6,7 +6,7 @@- We could not create logs from your bulk upload because of the following errors. Download the <%= govuk_link_to "specification", Forms::BulkUploadSales::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file. + We could not create logs from your bulk upload because of the following errors. Download the <%= govuk_link_to "specification", Forms::BulkUploadForm::PrepareYourFile.new(year: @bulk_upload.year, log_type: "sales").specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
File name: <%= @bulk_upload.filename %>
diff --git a/app/views/bulk_upload_shared/guidance.html.erb b/app/views/bulk_upload_shared/guidance.html.erb index 54e8063f0..1463f63b9 100644 --- a/app/views/bulk_upload_shared/guidance.html.erb +++ b/app/views/bulk_upload_shared/guidance.html.erb @@ -28,29 +28,14 @@ <%= accordion.with_section(heading_text: "Using the bulk upload template") do %>For each collection year, we publish a bulk upload template and specification.
- <% if @form.year == 2023 %> -The bulk upload templates contain 7 or 8 rows of ‘headers’ with information about how to fill in the template, including:
- <% else %> -The bulk upload templates contain 8 rows of ‘headers’ with information about how to fill in the template, including:
- <% end %> +The bulk upload templates contain 8 rows of ‘headers’ with information about how to fill in the template, including:
<%= govuk_list ["the CORE form questions and their field numbers", "each field’s valid responses", "if/when certain fields can be left blank", "which fields are used to check for duplicate logs"], type: :bullet %>You can paste your data below the headers or copy the headers and insert them above the data in your file. The bulk upload fields start at column B. Leave column A blank.
Make sure that each column of data aligns with the corresponding question in the headers. We recommend ordering your data to match the headers, but you can also reorder the headers to match your data. When processing the file, we check what each column of data represents based on the headers above.
- <% if @form.year == 2023 %> -For 2023/24 uploads, there are 2 templates to choose from, a new template and a legacy template. They outline suggested ways of ordering your data.
-You must include the headers in your file when you upload, unless your data matches the exact order of the legacy template. If you choose to remove the headers, you must also remove the blank column A.
- -New template: In this template, the questions are in the same order as the 2023/24 paper form and web form. Use this template if your organisation is new to bulk upload or if your housing management system matches the new column ordering.
-<%= govuk_link_to "Download the lettings bulk upload template (2023 to 2024) – New question ordering", @form.lettings_template_path %>
-<%= govuk_link_to "Download the sales bulk upload template (2023 to 2024) – New question ordering", @form.sales_template_path %>
- -Legacy template: In this template, the questions are in the same order as the 2022/23 template, with new questions added on to the end. Use this template if you have not updated your system to match the new template yet.
- <% else %> -<%= govuk_link_to "Download the lettings bulk upload template (2024 to 2025)", @form.lettings_template_path %>
-<%= govuk_link_to "Download the sales bulk upload template (2024 to 2025)", @form.sales_template_path %>
- <% end %> +<%= govuk_link_to "Download the lettings bulk upload template (2024 to 2025)", @form.lettings_template_path %>
+<%= govuk_link_to "Download the sales bulk upload template (2024 to 2025)", @form.sales_template_path %>
<% end %> <%= accordion.with_section(heading_text: "Using the bulk upload specification") do %> diff --git a/app/views/layouts/rails_admin/_navigation.html.erb b/app/views/layouts/rails_admin/_navigation.html.erb new file mode 100644 index 000000000..6c5f77aa3 --- /dev/null +++ b/app/views/layouts/rails_admin/_navigation.html.erb @@ -0,0 +1,9 @@ +<%= govuk_header( + classes: "app-header app-header--orange", + homepage_url: Rails.application.routes.url_helpers.root_path, + navigation_classes: "govuk-header__navigation--end", + ) do |component| + component.with_product_name(name: t("service_name")) + component.with_navigation_item(text: "Your account", href: Rails.application.routes.url_helpers.account_path) + component.with_navigation_item(text: "Sign out", href: Rails.application.routes.url_helpers.destroy_user_session_path) + end %> diff --git a/app/views/layouts/rails_admin/application.html.erb b/app/views/layouts/rails_admin/application.html.erb new file mode 100644 index 000000000..27dc747fd --- /dev/null +++ b/app/views/layouts/rails_admin/application.html.erb @@ -0,0 +1,70 @@ +