diff --git a/app/models/form/sales/questions/staircase_count.rb b/app/models/form/sales/questions/staircase_count.rb index bad35be2e..07095cd6a 100644 --- a/app/models/form/sales/questions/staircase_count.rb +++ b/app/models/form/sales/questions/staircase_count.rb @@ -6,6 +6,7 @@ class Form::Sales::Questions::StaircaseCount < ::Form::Question @type = "numeric" @width = 2 @min = 2 + @max = 10 @step = 1 @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 3c5e3f2b9..9c5b85e3a 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -32,6 +32,14 @@ module Validations::Sales::SaleInformationValidations 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) return unless record.fromprop && record.frombeds @@ -348,6 +356,18 @@ module Validations::Sales::SaleInformationValidations 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) if strict (expected - actual).abs > tolerance diff --git a/config/locales/validations/sales/sale_information.en.yml b/config/locales/validations/sales/sale_information.en.yml index 20aca17d2..ceed78646 100644 --- a/config/locales/validations/sales/sale_information.en.yml +++ b/config/locales/validations/sales/sale_information.en.yml @@ -17,6 +17,8 @@ en: exdate: 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." + initialpurchase: + must_be_after_1980: "The initial purchase date must be after January 1, 1980." fromprop: previous_property_type_bedsit: "A bedsit cannot have more than 1 bedroom." frombeds: @@ -123,3 +125,8 @@ en: 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_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."