Browse Source

reset location fields when postode not known

pull/170/head
Kat 4 years ago
parent
commit
1cb525c618
  1. 27
      app/models/case_log.rb
  2. 2
      app/models/constants/case_log.rb
  3. 2
      config/forms/2021_2022.json
  4. 3
      spec/models/case_log_spec.rb

27
app/models/case_log.rb

@ -213,7 +213,12 @@ private
self.renttype = RENT_TYPE_MAPPING[rent_type]
self.lettype = "#{renttype} #{needstype} #{owning_organisation['Org type']}" if renttype.present? && needstype.present? && owning_organisation["Org type"].present?
self.is_la_inferred = false if is_la_inferred.nil?
self.la = get_la(property_postcode)
if property_postcode.blank? || postcode_known == "No"
reset_location_fields
else
self.la = get_la(property_postcode)
end
self.totchild = get_totchild
self.totelder = get_totelder
self.totadult = get_totadult
@ -241,18 +246,24 @@ private
end
def get_la(postcode)
if postcode.present?
postcode_lookup = nil
Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) }
if postcode_lookup && postcode_lookup.info.present?
self.is_la_inferred = true
return postcode_lookup.admin_district
end
postcode_lookup = nil
Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) }
if postcode_lookup && postcode_lookup.info.present?
self.is_la_inferred = true
return postcode_lookup.admin_district
end
self.la = nil
self.is_la_inferred = false
end
def reset_location_fields
if is_la_inferred == true
self.la = nil
end
self.is_la_inferred = false
self.property_postcode = nil
end
def all_fields_completed?
mandatory_fields.none? { |_key, val| val.nil? }
end

2
app/models/constants/case_log.rb

@ -489,7 +489,7 @@ module Constants::CaseLog
"Tewkesbury" => "E07000083",
"Basingstoke and Deane" => "E07000084",
"East Hampshire" => "E07000085",
"Kings Lynn and West Norfolk" => "E07000146",
"King's Lynn and West Norfolk" => "E07000146",
"Eastleigh" => "E07000086",
"North Norfolk" => "E07000147",
"Norwich" => "E07000148",

2
config/forms/2021_2022.json

@ -1294,7 +1294,7 @@
"133": "Isles of Scilly",
"134": "Islington",
"135": "Kensington & Chelsea",
"136": "Kings Lynn & West Norfolk",
"136": "King's Lynn and West Norfolk",
"137": "Kingston-upon-Hull",
"138": "Kingston-upon-Thames",
"139": "Kirklees",

3
spec/models/case_log_spec.rb

@ -1031,6 +1031,7 @@ RSpec.describe Form, type: :model do
CaseLog.create({
managing_organisation: organisation,
owning_organisation: organisation,
postcode_known: "Yes",
property_postcode: "M1 1AE",
})
end
@ -1054,7 +1055,7 @@ RSpec.describe Form, type: :model do
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["property_postcode"]).to eq("")
expect(record_from_db["property_postcode"]).to eq(nil)
expect(address_case_log.la).to eq(nil)
expect(record_from_db["la"]).to eq(nil)
end

Loading…
Cancel
Save