Browse Source

Add validation to new questions firststair and numstair

pull/2793/head
Manny Dinssa 7 months ago
parent
commit
f9fc565c4b
  1. 1
      app/models/form/sales/questions/staircase_count.rb
  2. 20
      app/models/validations/sales/sale_information_validations.rb
  3. 7
      config/locales/validations/sales/sale_information.en.yml

1
app/models/form/sales/questions/staircase_count.rb

@ -6,6 +6,7 @@ class Form::Sales::Questions::StaircaseCount < ::Form::Question
@type = "numeric" @type = "numeric"
@width = 2 @width = 2
@min = 2 @min = 2
@max = 10
@step = 1 @step = 1
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
end end

20
app/models/validations/sales/sale_information_validations.rb

@ -32,6 +32,14 @@ module Validations::Sales::SaleInformationValidations
end end
end end
def validate_staircasing_initial_purchase_date(record)
return unless record.initialpurchase
if record.initialpurchase < Time.zone.local(1980, 1, 1)
record.errors.add :initialpurchase, I18n.t("validations.sales.sale_information.initialpurchase.must_be_after_1980")
end
end
def validate_previous_property_unit_type(record) def validate_previous_property_unit_type(record)
return unless record.fromprop && record.frombeds return unless record.fromprop && record.frombeds
@ -348,6 +356,18 @@ module Validations::Sales::SaleInformationValidations
end end
end end
def validate_number_of_staircase_transactions(record)
return unless record.numstair
if record.firststair == 1 && record.numstair >= 2 || record.firststair != 1 && record.numstair == 1
record.errors.add :numstair, I18n.t("validations.sales.sale_information.numstair.must_be_greater_than_one")
record.errors.add :firststair, I18n.t("validations.sales.sale_information.firststair.more_than_one_transaction")
end
if record.numstair > 10
record.errors.add :numstair, I18n.t("validations.sales.sale_information.numstair.must_be_ten_or_less")
end
end
def over_tolerance?(expected, actual, tolerance, strict: false) def over_tolerance?(expected, actual, tolerance, strict: false)
if strict if strict
(expected - actual).abs > tolerance (expected - actual).abs > tolerance

7
config/locales/validations/sales/sale_information.en.yml

@ -17,6 +17,8 @@ en:
exdate: exdate:
must_be_before_saledate: "Contract exchange date must be before sale completion date." must_be_before_saledate: "Contract exchange date must be before sale completion date."
must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before sale completion date." must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before sale completion date."
initialpurchase:
must_be_after_1980: "The initial purchase date must be after January 1, 1980."
fromprop: fromprop:
previous_property_type_bedsit: "A bedsit cannot have more than 1 bedroom." previous_property_type_bedsit: "A bedsit cannot have more than 1 bedroom."
frombeds: frombeds:
@ -123,3 +125,8 @@ en:
postcode_full: postcode_full:
value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London." value_over_discounted_london_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £136,400 for properties in London."
value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London." value_over_discounted_max: "The percentage discount multiplied by the purchase price is %{discount_value}. This figure should not be more than £102,400 for properties outside of London."
numstair:
must_be_greater_than_one: "The number of staircasing transactions must be greater than 1 when this is not the first staircasing transaction."
must_be_ten_or_less: "The number of staircasing transactions cannot be greater than 10."
firststair:
more_than_one_transaction: "The answer to 'Is this the first staircasing transaction?' cannot be 'yes' if the number of staircasing transactions is more than 1."

Loading…
Cancel
Save