Browse Source

Clear values if rp_dontknow conflict exists

pull/2955/head
Manny Dinssa 2 months ago
parent
commit
1ffce77acb
  1. 36
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  2. 36
      app/services/bulk_upload/lettings/year2025/row_parser.rb

36
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -762,17 +762,10 @@ private
end end
def validate_reasonable_preference_dont_know def validate_reasonable_preference_dont_know
other_reason_fields = %i[field_107 field_108 field_109 field_110] if rp_dontknow_conflict?
if field_106 == 1 errors.add(:field_111, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.dont_know"))
selected_reasons = other_reason_fields.select { |field| send(field) == 1 } %i[field_107 field_108 field_109 field_110].each do |field|
dont_know_selected = field_111 == 1 errors.add(field, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.other")) if send(field) == 1
if selected_reasons.any? && dont_know_selected
errors.add(:field_111, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.dont_know"))
selected_reasons.each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.other"))
end
end end
end end
end end
@ -1287,11 +1280,11 @@ private
attributes["ppostcode_full"] = ppostcode_full attributes["ppostcode_full"] = ppostcode_full
attributes["reasonpref"] = field_106 attributes["reasonpref"] = field_106
attributes["rp_homeless"] = field_107 attributes["rp_homeless"] = field_107 unless rp_dontknow_conflict?
attributes["rp_insan_unsat"] = field_108 attributes["rp_insan_unsat"] = field_108 unless rp_dontknow_conflict?
attributes["rp_medwel"] = field_109 attributes["rp_medwel"] = field_109 unless rp_dontknow_conflict?
attributes["rp_hardship"] = field_110 attributes["rp_hardship"] = field_110 unless rp_dontknow_conflict?
attributes["rp_dontknow"] = field_111 attributes["rp_dontknow"] = field_111 unless rp_dontknow_conflict?
attributes["cbl"] = cbl attributes["cbl"] = cbl
attributes["chr"] = chr attributes["chr"] = chr
@ -1678,4 +1671,15 @@ private
def bulk_upload_organisation def bulk_upload_organisation
Organisation.find(bulk_upload.organisation_id) Organisation.find(bulk_upload.organisation_id)
end end
def rp_dontknow_conflict?
other_reason_fields = %i[field_107 field_108 field_109 field_110]
if field_106 == 1
selected_reasons = other_reason_fields.select { |field| send(field) == 1 }
dont_know_selected = field_111 == 1
return true if selected_reasons.any? && dont_know_selected
end
false
end
end end

36
app/services/bulk_upload/lettings/year2025/row_parser.rb

@ -761,17 +761,10 @@ private
end end
def validate_reasonable_preference_dont_know def validate_reasonable_preference_dont_know
other_reason_fields = %i[field_107 field_108 field_109 field_110] if rp_dontknow_conflict?
if field_106 == 1 errors.add(:field_111, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.dont_know"))
selected_reasons = other_reason_fields.select { |field| send(field) == 1 } %i[field_107 field_108 field_109 field_110].each do |field|
dont_know_selected = field_111 == 1 errors.add(field, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.other")) if send(field) == 1
if selected_reasons.any? && dont_know_selected
errors.add(:field_111, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.dont_know"))
selected_reasons.each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.reasonpref.conflict.other"))
end
end end
end end
end end
@ -1284,11 +1277,11 @@ private
attributes["ppostcode_full"] = ppostcode_full attributes["ppostcode_full"] = ppostcode_full
attributes["reasonpref"] = field_106 attributes["reasonpref"] = field_106
attributes["rp_homeless"] = field_107 attributes["rp_homeless"] = field_107 unless rp_dontknow_conflict?
attributes["rp_insan_unsat"] = field_108 attributes["rp_insan_unsat"] = field_108 unless rp_dontknow_conflict?
attributes["rp_medwel"] = field_109 attributes["rp_medwel"] = field_109 unless rp_dontknow_conflict?
attributes["rp_hardship"] = field_110 attributes["rp_hardship"] = field_110 unless rp_dontknow_conflict?
attributes["rp_dontknow"] = field_111 attributes["rp_dontknow"] = field_111 unless rp_dontknow_conflict?
attributes["cbl"] = cbl attributes["cbl"] = cbl
attributes["chr"] = chr attributes["chr"] = chr
@ -1680,4 +1673,15 @@ private
"R" # refused "R" # refused
end end
end end
def rp_dontknow_conflict?
other_reason_fields = %i[field_107 field_108 field_109 field_110]
if field_106 == 1
selected_reasons = other_reason_fields.select { |field| send(field) == 1 }
dont_know_selected = field_111 == 1
return true if selected_reasons.any? && dont_know_selected
end
false
end
end end

Loading…
Cancel
Save