diff --git a/app/admin/organisations.rb b/app/admin/organisations.rb index bbf9efe90..3b106c1f0 100644 --- a/app/admin/organisations.rb +++ b/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 diff --git a/app/constants/db_enums.rb b/app/constants/db_enums.rb index 0dc271baf..ee5769409 100644 --- a/app/constants/db_enums.rb +++ b/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 diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 478626381..1f4a1fb36 100644 --- a/app/models/case_log.rb +++ b/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? diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 392f6366f..dc46faf93 100644 --- a/app/models/organisation.rb +++ b/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, diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 0ef875dc1..34af5078f 100644 --- a/config/forms/2021_2022.json +++ b/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": "", diff --git a/db/migrate/20211201114814_change_lettype_derived_field.rb b/db/migrate/20211201114814_change_lettype_derived_field.rb new file mode 100644 index 000000000..f9dc2f4ba --- /dev/null +++ b/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 diff --git a/db/migrate/20211201144335_rename_org_type.rb b/db/migrate/20211201144335_rename_org_type.rb new file mode 100644 index 000000000..c4a7b6a3e --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index d31322f7c..c9570f994 100644 --- a/db/schema.rb +++ b/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" diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 7f85e2096..cea3e9076 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/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", diff --git a/spec/controllers/admin/organisations_controller_spec.rb b/spec/controllers/admin/organisations_controller_spec.rb index 276742898..2afa99b44 100644 --- a/spec/controllers/admin/organisations_controller_spec.rb +++ b/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 diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index dd636f9d9..80f05b7da 100644 --- a/spec/factories/case_log.rb +++ b/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" } diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb index 91e4179e7..046a26724 100644 --- a/spec/factories/organisation.rb +++ b/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" } diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index a01ae395a..e70a7a2f0 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -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" } } diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index b05d925c1..b94710b1b 100644 --- a/spec/models/case_log_spec.rb +++ b/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 diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index c5f2aaffc..1194483d9 100644 --- a/spec/models/organisation_spec.rb +++ b/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