Browse Source

Infer lettype

pull/127/head
Kat 4 years ago
parent
commit
c6f9edf996
  1. 24
      app/constants/db_enums.rb
  2. 4
      app/models/case_log.rb
  3. 3
      app/models/organisation.rb
  4. 1
      docs/api/DLUHC-CORE-Data.v1.json
  5. 2
      spec/factories/case_log.rb
  6. 2
      spec/factories/organisation.rb
  7. 8
      spec/fixtures/complete_case_log.json
  8. 11
      spec/models/case_log_spec.rb

24
app/constants/db_enums.rb

@ -740,4 +740,28 @@ module DbEnums
"Supported Housing" => 2,
}
end
def self.org_type
{
"LA" => 1,
"PRP" => 2,
}
end
def self.lettype
{
"Social Rent General Needs PRP" => 1,
"Social Rent Supported Housing PRP" => 2,
"Social Rent General Needs LA" => 3,
"Social Rent Supported Housing LA" => 4,
"Affordable Rent General Needs PRP" => 5,
"Affordable Rent Supported Housing PRP" => 6,
"Affordable Rent General Needs LA" => 7,
"Affordable Rent Supported Housing LA" => 8,
"Intermediate Rent General Needs PRP" => 9,
"Intermediate Rent Supported Housing PRP" => 10,
"Intermediate Rent General Needs LA" => 11,
"Intermediate Rent Supported Housing LA" => 12,
}
end
end

4
app/models/case_log.rb

@ -111,8 +111,9 @@ class CaseLog < ApplicationRecord
enum incref: DbEnums.polar, _suffix: true
enum renttype: DbEnums.renttype, _suffix: true
enum needstype: DbEnums.needstype, _suffix: true
enum lettype: DbEnums.lettype, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype].freeze
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype].freeze
OPTIONAL_FIELDS = %w[do_you_know_the_postcode
do_you_know_the_local_authority
first_time_property_let_as_social_housing].freeze
@ -191,6 +192,7 @@ private
self.incref = 1 if net_income_known == "Prefer not to say"
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?
end
def all_fields_completed?

3
app/models/organisation.rb

@ -3,6 +3,9 @@ class Organisation < ApplicationRecord
has_many :owned_case_logs, class_name: "CaseLog", foreign_key: "owning_organisation_id"
has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id"
include DbEnums
enum org_type: DbEnums.org_type, _suffix: true
def case_logs
CaseLog.for_organisation(self)
end

1
docs/api/DLUHC-CORE-Data.v1.json

@ -306,7 +306,6 @@
"startertenancy": "No",
"tenancylength": "No",
"tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"la": "Barnet",
"previous_postcode": "NW1 5TY",

2
spec/factories/case_log.rb

@ -52,7 +52,7 @@ FactoryBot.define do
startertenancy { "No" }
tenancylength { 5 }
tenancy { "Secure (including flexible)" }
lettype { "Affordable Rent - General Needs" }
lettype { "Affordable Rent General Needs LA" }
landlord { "This landlord" }
previous_postcode { "SE2 6RT" }
rsnvac { "Tenant abandoned property" }

2
spec/factories/organisation.rb

@ -1,7 +1,7 @@
FactoryBot.define do
factory :organisation do
name { "DLUHC" }
org_type { 1 }
org_type { "LA" }
address_line1 { "2 Marsham Street" }
address_line2 { "London" }
postcode { "SW1P 4DF" }

8
spec/fixtures/complete_case_log.json vendored

@ -54,7 +54,6 @@
"startertenancy": "No",
"tenancylength": "5",
"tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"la": "Barnet",
"property_postcode": "NW1 5TY",
@ -126,9 +125,9 @@
"property_owner_organisation": "",
"property_manager_organisation": "",
"sale_or_letting": "",
"rent_type": "",
"rent_type": "Social Rent",
"intermediate_rent_product_name": "",
"needstype": "",
"needstype": "General Needs",
"sale_completion_date": "01/01/2020",
"purchaser_code": "",
"propcode": "123",
@ -143,7 +142,6 @@
"property_wheelchair_accessible": "Yes",
"void_or_renewal_date": "05/05/2020",
"tenant_same_property_renewal": "Yes",
"new_build_handover_date": "01/01/2019",
"renttype": 1
"new_build_handover_date": "01/01/2019"
}
}

11
spec/models/case_log_spec.rb

@ -838,7 +838,7 @@ RSpec.describe Form, type: :model do
describe "derived variables" do
require "date"
let(:organisation) { FactoryBot.create(:organisation) }
let(:organisation) { FactoryBot.create(:organisation, org_type: "PRP") }
let!(:case_log) do
CaseLog.create({
managing_organisation: organisation,
@ -851,6 +851,7 @@ RSpec.describe Form, type: :model do
net_income_known: "Prefer not to say",
other_hhmemb: 6,
rent_type: "London Living Rent",
needstype: "General Needs",
})
end
@ -903,5 +904,13 @@ RSpec.describe Form, type: :model do
expect(case_log.renttype).to eq("Intermediate Rent")
expect(record_from_db["renttype"]).to eq(3)
end
it "correctly derives and saves lettype" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq("Intermediate Rent General Needs PRP")
expect(record_from_db["lettype"]).to eq(9)
end
end
end

Loading…
Cancel
Save