Browse Source

reset location fields when postode not known

pull/170/head
Kat 4 years ago
parent
commit
1cb525c618
  1. 13
      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

13
app/models/case_log.rb

@ -213,7 +213,12 @@ private
self.renttype = RENT_TYPE_MAPPING[rent_type] 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.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.is_la_inferred = false if is_la_inferred.nil?
if property_postcode.blank? || postcode_known == "No"
reset_location_fields
else
self.la = get_la(property_postcode) self.la = get_la(property_postcode)
end
self.totchild = get_totchild self.totchild = get_totchild
self.totelder = get_totelder self.totelder = get_totelder
self.totadult = get_totadult self.totadult = get_totadult
@ -241,16 +246,22 @@ private
end end
def get_la(postcode) def get_la(postcode)
if postcode.present?
postcode_lookup = nil postcode_lookup = nil
Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) } Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) }
if postcode_lookup && postcode_lookup.info.present? if postcode_lookup && postcode_lookup.info.present?
self.is_la_inferred = true self.is_la_inferred = true
return postcode_lookup.admin_district return postcode_lookup.admin_district
end end
self.la = nil
self.is_la_inferred = false
end end
def reset_location_fields
if is_la_inferred == true
self.la = nil self.la = nil
end
self.is_la_inferred = false self.is_la_inferred = false
self.property_postcode = nil
end end
def all_fields_completed? def all_fields_completed?

2
app/models/constants/case_log.rb

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

2
config/forms/2021_2022.json

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

3
spec/models/case_log_spec.rb

@ -1031,6 +1031,7 @@ RSpec.describe Form, type: :model do
CaseLog.create({ CaseLog.create({
managing_organisation: organisation, managing_organisation: organisation,
owning_organisation: organisation, owning_organisation: organisation,
postcode_known: "Yes",
property_postcode: "M1 1AE", property_postcode: "M1 1AE",
}) })
end end
@ -1054,7 +1055,7 @@ RSpec.describe Form, type: :model do
address_case_log.reload 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] 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(address_case_log.la).to eq(nil)
expect(record_from_db["la"]).to eq(nil) expect(record_from_db["la"]).to eq(nil)
end end

Loading…
Cancel
Save