From 7a96326cf3d4ff8448e77a797c25d6c412c6faf3 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 8 Feb 2023 10:47:56 +0000 Subject: [PATCH] CLDC-1918 Add 2023/24 sales form (#1273) * Add next years form to the form handler * Disable collection window validation in non prod/test * fix the years in the correct file * Undo year bulk upload change --- app/models/form.rb | 4 ++-- app/models/form_handler.rb | 6 +++--- app/models/forms/bulk_upload_sales/year.rb | 2 +- app/models/validations/sales/setup_validations.rb | 2 +- config/initializers/feature_toggle.rb | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index 456f25eda..3da85d52e 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -5,6 +5,8 @@ class Form def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings") if sales_or_start_year_after_2022?(type, start_year) + @start_date = Time.zone.local(start_year, 4, 1) + @end_date = Time.zone.local(start_year + 1, 7, 1) @setup_sections = type == "sales" ? [Form::Sales::Sections::Setup.new(nil, nil, self)] : [Form::Lettings::Sections::Setup.new(nil, nil, self)] @form_sections = sections_in_form.map { |sec| sec.new(nil, nil, self) } @type = type @@ -12,8 +14,6 @@ class Form @subsections = sections.flat_map(&:subsections) @pages = subsections.flat_map(&:pages) @questions = pages.flat_map(&:questions) - @start_date = Time.zone.local(start_year, 4, 1) - @end_date = Time.zone.local(start_year + 1, 7, 1) @form_definition = { "form_type" => type, "start_date" => start_date, diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 75893f193..15ec6b8fd 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -28,10 +28,10 @@ class FormHandler ] current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales") previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales") - { - "current_sales" => current_form, + next_form = Form.new(nil, current_collection_start_year + 1, sales_sections, "sales") + { "current_sales" => current_form, "previous_sales" => previous_form, - } + "next_sales" => next_form } end def lettings_forms diff --git a/app/models/forms/bulk_upload_sales/year.rb b/app/models/forms/bulk_upload_sales/year.rb index 2d4b48e4a..86b8967b7 100644 --- a/app/models/forms/bulk_upload_sales/year.rb +++ b/app/models/forms/bulk_upload_sales/year.rb @@ -34,7 +34,7 @@ module Forms private def possible_years - FormHandler.instance.sales_forms.values.map { |form| form.start_date.year }.sort.reverse + [FormHandler.instance.sales_forms["current_sales"].start_date.year, FormHandler.instance.sales_forms["previous_sales"].start_date.year] end end end diff --git a/app/models/validations/sales/setup_validations.rb b/app/models/validations/sales/setup_validations.rb index 0ae1f43ea..dadf85650 100644 --- a/app/models/validations/sales/setup_validations.rb +++ b/app/models/validations/sales/setup_validations.rb @@ -4,7 +4,7 @@ module Validations::Sales::SetupValidations def validate_saledate(record) return unless record.saledate && date_valid?("saledate", record) - unless Time.zone.local(2022, 4, 1) <= record.saledate && record.saledate < Time.zone.local(2023, 4, 1) + unless record.saledate.between?(Time.zone.local(2022, 4, 1), Time.zone.local(2023, 3, 31)) || !FeatureToggle.saledate_collection_window_validation_enabled? record.errors.add :saledate, I18n.t("validations.setup.saledate.financial_year") end end diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index 3ea8332bd..37f6aa653 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -7,6 +7,10 @@ class FeatureToggle Rails.env.production? || Rails.env.test? end + def self.saledate_collection_window_validation_enabled? + Rails.env.production? || Rails.env.test? + end + def self.sales_log_enabled? !Rails.env.production? end