Browse Source

Disable collection window validation in non prod/test

pull/1273/head
Kat 3 years ago
parent
commit
bfd6e36518
  1. 4
      app/models/form.rb
  2. 2
      app/models/validations/sales/setup_validations.rb
  3. 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,

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