|
|
|
|
@ -121,7 +121,7 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
enum postcode_known: POLAR, _suffix: true |
|
|
|
|
enum la_known: POLAR, _suffix: true |
|
|
|
|
|
|
|
|
|
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype].freeze |
|
|
|
|
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype is_la_inferred].freeze |
|
|
|
|
OPTIONAL_FIELDS = %w[postcode_known |
|
|
|
|
la_known |
|
|
|
|
first_time_property_let_as_social_housing].freeze |
|
|
|
|
@ -197,6 +197,7 @@ private
|
|
|
|
|
self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? |
|
|
|
|
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.present? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@ -204,7 +205,10 @@ private
|
|
|
|
|
uri = URI("https://api.os.uk/search/places/v1/postcode?key=#{ENV['OS_PLACES_API_KEY']}&postcode=#{postcode}&dataset=LPI") |
|
|
|
|
res = Net::HTTP.get_response(uri) |
|
|
|
|
response_body = JSON.parse(res.body) |
|
|
|
|
response_body["results"][0]["LPI"]["ADMINISTRATIVE_AREA"].downcase.capitalize if res.is_a?(Net::HTTPSuccess) && (response_body["header"]["totalresults"]).to_i.positive? |
|
|
|
|
if res.is_a?(Net::HTTPSuccess) && (response_body["header"]["totalresults"]).to_i.positive? |
|
|
|
|
self.is_la_inferred = true |
|
|
|
|
response_body["results"][0]["LPI"]["ADMINISTRATIVE_AREA"].downcase.capitalize |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def all_fields_completed? |
|
|
|
|
|