Browse Source

CLDC-4168: Add R override to BU

pull/3195/head
samyou-softwire 1 month ago
parent
commit
2c2ace8f4a
  1. 4
      app/models/derived_variables/sales_log_variables.rb
  2. 4
      app/models/sales_log.rb
  3. 46
      app/services/bulk_upload/sales/year2026/row_parser.rb
  4. 2
      config/locales/validations/sales/2026/bulk_upload.en.yml

4
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

4
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

46
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

2
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"

Loading…
Cancel
Save