diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb index a31cfab61..9ad8ecc74 100644 --- a/app/models/derived_variables/sales_log_variables.rb +++ b/app/models/derived_variables/sales_log_variables.rb @@ -98,6 +98,10 @@ module DerivedVariables::SalesLogVariables self.numstair = is_firststair? ? 1 : nil if numstair == 1 && firststair_changed? self.mrent = 0 if stairowned_100? + if buyer_not_interviewed_changed_to_interviewed_and_mortgage_length_known? + self.mortgage_length_known = 0 + end + set_encoded_derived_values!(DEPENDENCIES) end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index cf9e0dd44..d67937aa4 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -390,6 +390,10 @@ class SalesLog < Log proptype_changed? && proptype_was == 2 end + def buyer_not_interviewed_changed_to_interviewed_and_mortgage_length_known? + noint_changed? && noint_was == 1 && !buyer_not_interviewed? && mortlen.present? + end + def shared_ownership_scheme? ownershipsch == 1 end diff --git a/app/services/bulk_upload/sales/year2026/row_parser.rb b/app/services/bulk_upload/sales/year2026/row_parser.rb index 08d56fe37..6a46eceee 100644 --- a/app/services/bulk_upload/sales/year2026/row_parser.rb +++ b/app/services/bulk_upload/sales/year2026/row_parser.rb @@ -247,7 +247,7 @@ class BulkUpload::Sales::Year2026::RowParser attribute :field_87, :decimal attribute :field_88, :integer attribute :field_89, :decimal - attribute :field_90, :integer + attribute :field_90, :string attribute :field_91, :decimal attribute :field_92, :decimal attribute :field_93, :decimal @@ -277,7 +277,7 @@ class BulkUpload::Sales::Year2026::RowParser attribute :field_115, :decimal attribute :field_116, :integer attribute :field_117, :decimal - attribute :field_118, :integer + attribute :field_118, :string attribute :field_119, :integer attribute :field_120, :decimal attribute :field_121, :decimal @@ -416,6 +416,22 @@ class BulkUpload::Sales::Year2026::RowParser }, on: :before_log + validates :field_90, + if: :shared_ownership?, + format: { + with: /\A(\d+|R)\z/, + message: I18n.t("#{ERROR_BASE_KEY}.mortlen.invalid"), + }, + on: :after_log + + validates :field_118, + if: :discounted_ownership?, + format: { + with: /\A(\d+|R)\z/, + message: I18n.t("#{ERROR_BASE_KEY}.mortlen.invalid"), + }, + on: :after_log + validate :validate_buyer1_economic_status, on: :before_log validate :validate_buyer2_economic_status, on: :before_log validate :validate_valid_radio_option, on: :before_log @@ -755,6 +771,7 @@ private hb: %i[field_74], mortlen: mortlen_fields, + mortgage_length_known: mortlen_fields, proplen: proplen_fields, jointmore: %i[field_13], @@ -932,6 +949,7 @@ private attributes["hb"] = field_74 attributes["mortlen"] = mortlen + attributes["mortgage_length_known"] = mortgage_length_known attributes["proplen"] = proplen if proplen&.positive? attributes["proplen_asked"] = attributes["proplen"].present? ? 0 : 1 @@ -1151,9 +1169,29 @@ private end def mortlen - return field_90 if shared_ownership? + value = if shared_ownership? + field_90 + elsif discounted_ownership? + field_118 + end - field_118 if discounted_ownership? + return nil if value == "R" + + value + end + + def mortgage_length_known + value = if shared_ownership? + field_90 + elsif discounted_ownership? + field_118 + end + + if value == "R" + 1 + else + 0 + end end def proplen diff --git a/config/locales/validations/sales/2026/bulk_upload.en.yml b/config/locales/validations/sales/2026/bulk_upload.en.yml index c5c96818a..3cdb6b877 100644 --- a/config/locales/validations/sales/2026/bulk_upload.en.yml +++ b/config/locales/validations/sales/2026/bulk_upload.en.yml @@ -44,3 +44,5 @@ en: not_answered: "Enter either the UPRN or the full address." nationality: invalid: "Select a valid nationality." + mortlen: + invalid: "Mortgage length must be a number or the letter R"