Browse Source

Cldc 647 lettype derived variable (#127)

* Run migrations

* Infer lettype

* Rename org_type column

* Change misssed org_type

* Change domain variable name to org_type

* Humanise the variable name"
pull/130/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
64c45f091a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/admin/organisations.rb
  2. 31
      app/constants/db_enums.rb
  3. 5
      app/models/case_log.rb
  4. 5
      app/models/organisation.rb
  5. 22
      config/forms/2021_2022.json
  6. 19
      db/migrate/20211201114814_change_lettype_derived_field.rb
  7. 5
      db/migrate/20211201144335_rename_org_type.rb
  8. 10
      db/schema.rb
  9. 1
      docs/api/DLUHC-CORE-Data.v1.json
  10. 2
      spec/controllers/admin/organisations_controller_spec.rb
  11. 4
      spec/factories/case_log.rb
  12. 1
      spec/factories/organisation.rb
  13. 8
      spec/fixtures/complete_case_log.json
  14. 11
      spec/models/case_log_spec.rb
  15. 2
      spec/models/organisation_spec.rb

4
app/admin/organisations.rb

@ -2,7 +2,7 @@ ActiveAdmin.register Organisation do
permit_params do
permitted = %i[name
phone
org_type
providertype
address_line1
address_line2
postcode
@ -17,7 +17,7 @@ ActiveAdmin.register Organisation do
selectable_column
id_column
column :name
column :org_type
column "Org type", :providertype
column "Address Line 1", :address_line1
column "Address Line 2", :address_line2
column :postcode

31
app/constants/db_enums.rb

@ -733,4 +733,35 @@ module DbEnums
"Intermediate Rent" => 3,
}
end
def self.needstype
{
"General Needs" => 1,
"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

5
app/models/case_log.rb

@ -110,8 +110,10 @@ class CaseLog < ApplicationRecord
enum builtype: DbEnums.builtype, _suffix: true
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
@ -190,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?

5
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
@ -24,7 +27,7 @@ class Organisation < ApplicationRecord
name: name,
address: address_string,
telephone_number: phone,
type: org_type,
type: "Org type",
local_authorities_operated_in: local_authorities,
holds_own_stock: holds_own_stock,
other_stock_owners: other_stock_owners,

22
config/forms/2021_2022.json

@ -133,7 +133,7 @@
"header": "What is intermediate rent product name?",
"type": "text"
},
"needs_type": {
"needstype": {
"check_answer_label": "What is the needs type?",
"header": "What is the needs type?",
"hint_text": "",
@ -1065,26 +1065,6 @@
}
}
},
"letting_type": {
"header": "",
"description": "",
"questions": {
"lettype": {
"check_answer_label": "Type of letting",
"header": "Which type of letting is this?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Social Rent - General Needs",
"1": "Social Rent - Supporting Housing",
"2": "Affordable Rent - General Needs",
"3": "Affordable Rent - Supporting Housing",
"4": "Rent To Buy - General Needs",
"5": "Rent To Buy - Supported Housing"
}
}
}
},
"letting_provider": {
"header": "",
"description": "",

19
db/migrate/20211201114814_change_lettype_derived_field.rb

@ -0,0 +1,19 @@
class ChangeLettypeDerivedField < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |t|
t.remove :needs_type
t.column :needstype, :integer
t.remove :lettype
t.column :lettype, :integer
end
end
def down
change_table :case_logs, bulk: true do |t|
t.column :needs_type, :string
t.remove :needstype
t.remove :lettype
t.column :lettype, :string
end
end
end

5
db/migrate/20211201144335_rename_org_type.rb

@ -0,0 +1,5 @@
class RenameOrgType < ActiveRecord::Migration[6.1]
def change
rename_column :organisations, :org_type, :providertype
end
end

10
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_30_144840) do
ActiveRecord::Schema.define(version: 2021_12_01_144335) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -77,7 +77,6 @@ ActiveRecord::Schema.define(version: 2021_11_30_144840) do
t.integer "startertenancy"
t.integer "tenancylength"
t.integer "tenancy"
t.string "lettype"
t.integer "landlord"
t.string "previous_postcode"
t.integer "rsnvac"
@ -137,7 +136,6 @@ ActiveRecord::Schema.define(version: 2021_11_30_144840) do
t.string "tenant_same_property_renewal"
t.string "rent_type"
t.string "intermediate_rent_product_name"
t.string "needs_type"
t.string "purchaser_code"
t.integer "reason"
t.string "propcode"
@ -165,10 +163,12 @@ ActiveRecord::Schema.define(version: 2021_11_30_144840) do
t.string "why_dont_you_know_la"
t.integer "unitletas"
t.integer "builtype"
t.datetime "property_void_date"
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.datetime "property_void_date"
t.integer "renttype"
t.integer "needstype"
t.integer "lettype"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
@ -177,7 +177,7 @@ ActiveRecord::Schema.define(version: 2021_11_30_144840) do
create_table "organisations", force: :cascade do |t|
t.string "name"
t.integer "phone"
t.integer "org_type"
t.integer "providertype"
t.string "address_line1"
t.string "address_line2"
t.string "postcode"

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/controllers/admin/organisations_controller_spec.rb

@ -36,7 +36,7 @@ describe Admin::OrganisationsController, type: :controller do
it "creates a new admin users" do
expect(page).to have_field("organisation_name")
expect(page).to have_field("organisation_org_type")
expect(page).to have_field("organisation_providertype")
expect(page).to have_field("organisation_phone")
end
end

4
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" }
@ -113,7 +113,7 @@ FactoryBot.define do
tenant_same_property_renewal { 1 }
rent_type { 1 }
intermediate_rent_product_name { 2 }
needs_type { 1 }
needstype { 1 }
purchaser_code { 798_794 }
reason { "Permanently decanted from another property owned by this landlord" }
propcode { "123" }

1
spec/factories/organisation.rb

@ -1,7 +1,6 @@
FactoryBot.define do
factory :organisation do
name { "DLUHC" }
org_type { 1 }
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": "",
"needs_type": "",
"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

2
spec/models/organisation_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Organisation, type: :model do
let(:organisation) { user.organisation }
it "has expected fields" do
expect(organisation.attribute_names).to include("name", "phone", "org_type")
expect(organisation.attribute_names).to include("name", "phone", "Org type")
end
it "has users" do

Loading…
Cancel
Save