Browse Source

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
pull/1282/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
7a96326cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/form.rb
  2. 6
      app/models/form_handler.rb
  3. 2
      app/models/forms/bulk_upload_sales/year.rb
  4. 2
      app/models/validations/sales/setup_validations.rb
  5. 4
      config/initializers/feature_toggle.rb

4
app/models/form.rb

@ -5,6 +5,8 @@ class Form
def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings") def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings")
if sales_or_start_year_after_2022?(type, start_year) 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)] @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) } @form_sections = sections_in_form.map { |sec| sec.new(nil, nil, self) }
@type = type @type = type
@ -12,8 +14,6 @@ class Form
@subsections = sections.flat_map(&:subsections) @subsections = sections.flat_map(&:subsections)
@pages = subsections.flat_map(&:pages) @pages = subsections.flat_map(&:pages)
@questions = pages.flat_map(&:questions) @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_definition = {
"form_type" => type, "form_type" => type,
"start_date" => start_date, "start_date" => start_date,

6
app/models/form_handler.rb

@ -28,10 +28,10 @@ class FormHandler
] ]
current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales") 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") previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales")
{ next_form = Form.new(nil, current_collection_start_year + 1, sales_sections, "sales")
"current_sales" => current_form, { "current_sales" => current_form,
"previous_sales" => previous_form, "previous_sales" => previous_form,
} "next_sales" => next_form }
end end
def lettings_forms def lettings_forms

2
app/models/forms/bulk_upload_sales/year.rb

@ -34,7 +34,7 @@ module Forms
private private
def possible_years 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 end
end end

2
app/models/validations/sales/setup_validations.rb

@ -4,7 +4,7 @@ module Validations::Sales::SetupValidations
def validate_saledate(record) def validate_saledate(record)
return unless record.saledate && date_valid?("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") record.errors.add :saledate, I18n.t("validations.setup.saledate.financial_year")
end end
end end

4
config/initializers/feature_toggle.rb

@ -7,6 +7,10 @@ class FeatureToggle
Rails.env.production? || Rails.env.test? Rails.env.production? || Rails.env.test?
end end
def self.saledate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test?
end
def self.sales_log_enabled? def self.sales_log_enabled?
!Rails.env.production? !Rails.env.production?
end end

Loading…
Cancel
Save