Browse Source

Removes the landlord field

pull/470/head
Stéphane Meny 3 years ago
parent
commit
26cd768669
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 1
      app/models/bulk_upload.rb
  2. 15
      app/models/case_log.rb
  3. 19
      app/models/validations/financial_validations.rb
  4. 4
      app/models/validations/household_validations.rb
  5. 40
      config/locales/en.yml
  6. 2
      db/migrate/20220411092231_update_case_logs_fields.rb
  7. 1
      db/schema.rb
  8. 4
      spec/factories/case_log.rb
  9. 1
      spec/fixtures/exports/case_logs.xml
  10. 54
      spec/models/case_log_spec.rb
  11. 36
      spec/models/validations/financial_validations_spec.rb
  12. 16
      spec/models/validations/household_validations_spec.rb

1
app/models/bulk_upload.rb

@ -57,7 +57,6 @@ class BulkUpload
def map_row(row)
{
lettype: row[1],
landlord: row[2],
# reg_num_la_core_code: row[3],
# managementgroup: row[4],
# schemecode: row[5],

15
app/models/case_log.rb

@ -334,16 +334,6 @@ class CaseLog < ApplicationRecord
hb == 3
end
def this_landlord?
# 1: This landlord
landlord == 1
end
def other_landlord?
# 2: Another RP (HA/LA)
landlord == 2
end
def local_housing_referral?
# 3: PRP lettings only - Nominated by local housing authority
referral == 3
@ -485,11 +475,6 @@ private
self["ecstat#{idx}"] = nil
end
end
if owning_organisation == managing_organisation
self.landlord = 1
else
self.landlord = 2
end
end
def process_postcode_changes!

19
app/models/validations/financial_validations.rb

@ -84,46 +84,47 @@ private
CHARGE_MAXIMUMS = {
scharge: {
this_landlord: {
private_registered_provider: {
general_needs: 55,
supported_housing: 280,
},
other_landlord: {
local_authority: {
general_needs: 45,
supported_housing: 165,
},
},
pscharge: {
this_landlord: {
private_registered_provider: {
general_needs: 30,
supported_housing: 200,
},
other_landlord: {
local_authority: {
general_needs: 35,
supported_housing: 75,
},
},
supcharg: {
this_landlord: {
private_registered_provider: {
general_needs: 40,
supported_housing: 465,
},
other_landlord: {
local_authority: {
general_needs: 60,
supported_housing: 120,
},
},
}.freeze
LANDLORD_VALUES = { 1 => :this_landlord, 2 => :other_landlord }.freeze
PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze
NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze
def validate_charges(record)
provider_type = record.owning_organisation.provider_type_before_type_cast
%i[scharge pscharge supcharg].each do |charge|
maximum = CHARGE_MAXIMUMS.dig(charge, LANDLORD_VALUES[record.landlord], NEEDSTYPE_VALUES[record.needstype])
maximum = CHARGE_MAXIMUMS.dig(charge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[record.needstype])
if maximum.present? && record[:period].present? && record[charge].present? && !weekly_value_in_range(record, charge, 0.0, maximum)
record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{LANDLORD_VALUES[record.landlord]}.#{NEEDSTYPE_VALUES[record.needstype]}")
record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{PROVIDER_TYPE[provider_type]}.#{NEEDSTYPE_VALUES[record.needstype]}")
end
end
end

4
app/models/validations/household_validations.rb

@ -105,12 +105,12 @@ module Validations::HouseholdValidations
record.errors.add :homeless, I18n.t("validations.household.homeless.other.internal_transfer")
end
if record.is_internal_transfer? && record.this_landlord? && record.is_prevten_general_needs_tenancy?
if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_general_needs_tenancy?
record.errors.add :referral, I18n.t("validations.household.referral.la_general_needs.internal_transfer")
record.errors.add :prevten, I18n.t("validations.household.prevten.la_general_needs.internal_transfer")
end
if record.other_landlord? && record.local_housing_referral?
if record.owning_organisation.provider_type == "LA" && record.local_housing_referral?
record.errors.add :referral, I18n.t("validations.household.referral.prp.local_housing_referral")
end
end

40
config/locales/en.yml

@ -100,26 +100,26 @@ en:
rent:
less_than_double_shortfall: "Answer must be more than double the shortfall in basic rent"
scharge:
this_landlord:
general_needs: "Service charge must be between £0 and £55 per week if the landlord is the same and it is a general needs letting"
supported_housing: "Service charge must be between £0 and £280 per week if the landlord is the same and it is a supported housing letting"
other_landlord:
general_needs: "Service charge must be between £0 and £45 per week if the landlord is another registered provider and it is a general needs letting"
supported_housing: "Service charge must be between £0 and £165 per week if the landlord is another registered provider and it is a supported housing letting"
private_registered_provider:
general_needs: "Service charge must be between £0 and £55 per week if the landlord is a private registered provider and it is a general needs letting"
supported_housing: "Service charge must be between £0 and £280 per week if the landlord is a private registered provider and it is a supported housing letting"
local_authority:
general_needs: "Service charge must be between £0 and £45 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Service charge must be between £0 and £165 per week if the landlord is a local authority and it is a supported housing letting"
pscharge:
this_landlord:
general_needs: "Personal service charge must be between £0 and £30 per week if the landlord is the same and it is a general needs letting"
supported_housing: "Personal service charge must be between £0 and £200 per week if the landlord is the same and it is a supported housing letting"
other_landlord:
general_needs: "Personal service charge must be between £0 and £35 per week if the landlord is another registered provider and it is a general needs letting"
supported_housing: "Personal service charge must be between £0 and £75 per week if the landlord is another registered provider and it is a supported housing letting"
private_registered_provider:
general_needs: "Personal service charge must be between £0 and £30 per week if the landlord is a private registered provider and it is a general needs letting"
supported_housing: "Personal service charge must be between £0 and £200 per week if the landlord is a private registered provider and it is a supported housing letting"
local_authority:
general_needs: "Personal service charge must be between £0 and £35 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Personal service charge must be between £0 and £75 per week if the landlord is a local authority and it is a supported housing letting"
supcharg:
this_landlord:
general_needs: "Support charge must be between £0 and £40 per week if the landlord is the same and it is a general needs letting"
supported_housing: "Support charge must be between £0 and £465 per week if the landlord is the same and it is a supported housing letting"
other_landlord:
general_needs: "Support charge must be between £0 and £60 per week if the landlord is another registered provider and it is a general needs letting"
supported_housing: "Support charge must be between £0 and £120 per week if the landlord is another registered provider and it is a supported housing letting"
private_registered_provider:
general_needs: "Support charge must be between £0 and £40 per week if the landlord is a private registered provider and it is a general needs letting"
supported_housing: "Support charge must be between £0 and £465 per week if the landlord is a private registered provider and it is a supported housing letting"
local_authority:
general_needs: "Support charge must be between £0 and £60 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Support charge must be between £0 and £120 per week if the landlord is a local authority and it is a supported housing letting"
brent:
not_in_range: "Basic rent is outside of the expected range based on the lettings type, local authority and number of bedrooms"
la:
@ -182,7 +182,7 @@ en:
male_refuge: "Answer cannot be refuge as the lead tenant identifies as male"
internal_transfer: "Answer cannot be %{prevten} as you already told us this tenancy is an internal transfer"
la_general_needs:
internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as you already told us it's the same landlord on the tenancy agreement and it is an internal transfer"
internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as you already told us it's a private registered provider on the tenancy agreement and it is an internal transfer"
referral:
secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy"
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
@ -194,7 +194,7 @@ en:
la_general_needs:
internal_transfer: "Answer cannot be internal transfer as you already told us it's the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting"
prp:
local_housing_referral: "Answer cannot be 'nominated by a local housing authority' as you already told us it's another landlord on the tenancy agreement"
local_housing_referral: "Answer cannot be 'nominated by a local housing authority' as you already told us it is a local authority on the tenancy agreement"
homeless:
assessed:
internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer"

2
db/migrate/20220411092231_update_case_logs_fields.rb

@ -2,7 +2,7 @@ class UpdateCaseLogsFields < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.integer :old_form_id, :lar, :irproduct
t.remove :day, :month, :year, :vday, :vmonth, :vyear, :mrcday, :mrcmonth, :mrcyear, :other_hhmemb, :accessibility_requirements_prefer_not_to_say, type: :integer
t.remove :day, :month, :year, :vday, :vmonth, :vyear, :mrcday, :mrcmonth, :mrcyear, :other_hhmemb, :accessibility_requirements_prefer_not_to_say, :landlord, type: :integer
t.remove :ppostc1, :ppostc2, :postcode, :postcod2, type: :string
t.rename :intermediate_rent_product_name, :irproduct_other
t.rename :lawaitlist, :waityear

1
db/schema.rb

@ -86,7 +86,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_11_092231) do
t.integer "startertenancy"
t.integer "tenancylength"
t.integer "tenancy"
t.integer "landlord"
t.string "ppostcode_full"
t.integer "rsnvac"
t.integer "unittype_gn"

4
spec/factories/case_log.rb

@ -2,9 +2,6 @@ FactoryBot.define do
factory :case_log do
owning_organisation { FactoryBot.create(:organisation) }
managing_organisation { FactoryBot.create(:organisation) }
trait :same_landlord do
managing_organisation { owning_organisation }
end
trait :about_completed do
renewal { 0 }
needstype { 1 }
@ -58,7 +55,6 @@ FactoryBot.define do
startertenancy { 0 }
tenancylength { 5 }
tenancy { 1 }
landlord { 1 }
ppostcode_full { "SE2 6RT" }
rsnvac { 6 }
unittype_gn { 7 }

1
spec/fixtures/exports/case_logs.xml vendored

@ -44,7 +44,6 @@
<startertenancy>0</startertenancy>
<tenancylength>5</tenancylength>
<tenancy>1</tenancy>
<landlord>2</landlord>
<ppostcode_full>SE26RT</ppostcode_full>
<rsnvac>6</rsnvac>
<unittype_gn>7</unittype_gn>

54
spec/models/case_log_spec.rb

@ -234,25 +234,10 @@ RSpec.describe CaseLog do
expect(record_from_db["renttype"]).to eq(3)
end
context "when the owning and managing organisations are different" do
it "correctly derives and saves landlord" do
record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.landlord).to eq(2)
expect(record_from_db["landlord"]).to eq(2)
end
end
context "when the owning and managing organisations are the same" do
it "correctly derives and saves landlord based on owning_organisation provider_type" do
record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.landlord).to eq(1)
expect(record_from_db["landlord"]).to eq(1)
end
end
context "when deriving lettype" do
context "when the owning organisation is a PRP" do
before { case_log.owning_organisation.update!(provider_type: 2) }
context "when the rent type is intermediate rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 4, needstype: 2)
@ -332,17 +317,17 @@ RSpec.describe CaseLog do
end
it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 70, period: 2)
case_log.update!(pscharge: 60, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(35.0)
expect(record_from_db["wpschrge"]).to eq(35.0)
expect(case_log.wpschrge).to eq(30.0)
expect(record_from_db["wpschrge"]).to eq(30.0)
end
it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 100, period: 2)
case_log.update!(supcharg: 80, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(50.0)
expect(record_from_db["wsupchrg"]).to eq(50.0)
expect(case_log.wsupchrg).to eq(40.0)
expect(record_from_db["wsupchrg"]).to eq(40.0)
end
it "correctly derives and saves weekly total charge" do
@ -382,18 +367,18 @@ RSpec.describe CaseLog do
end
it "correctly derives floats" do
case_log.update!(supcharg: 60.12, pscharge: 60.13, scharge: 60.98, brent: 60.97, period: 2)
case_log.update!(supcharg: 60.12, pscharge: 50.13, scharge: 60.98, brent: 60.97, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(30.06)
expect(case_log.wpschrge).to eq(30.06)
expect(case_log.wpschrge).to eq(25.06)
expect(case_log.wscharge).to eq(30.49)
expect(case_log.wrent).to eq(30.49)
expect(case_log.wtcharge).to eq(121.1)
expect(case_log.wtcharge).to eq(116.1)
expect(record_from_db["wsupchrg"]).to eq(30.06)
expect(record_from_db["wpschrge"]).to eq(30.06)
expect(record_from_db["wpschrge"]).to eq(25.06)
expect(record_from_db["wscharge"]).to eq(30.49)
expect(record_from_db["wrent"]).to eq(30.49)
expect(record_from_db["wtcharge"]).to eq(121.1)
expect(record_from_db["wtcharge"]).to eq(116.1)
end
end
@ -1030,24 +1015,24 @@ RSpec.describe CaseLog do
end
it "correctly derives floats" do
case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 1)
case_log.update!(supcharg: 30.12, pscharge: 25.13, scharge: 30.98, brent: 100.97, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(30.12)
expect(case_log.wpschrge).to eq(30.13)
expect(case_log.wpschrge).to eq(25.13)
expect(case_log.wscharge).to eq(30.98)
expect(case_log.wrent).to eq(100.97)
expect(case_log.wtcharge).to eq(192.2)
expect(case_log.wtcharge).to eq(187.2)
expect(record_from_db["wsupchrg"]).to eq(30.12)
expect(record_from_db["wpschrge"]).to eq(30.13)
expect(record_from_db["wpschrge"]).to eq(25.13)
expect(record_from_db["wscharge"]).to eq(30.98)
expect(record_from_db["wrent"]).to eq(100.97)
expect(record_from_db["wtcharge"]).to eq(192.2)
expect(record_from_db["wtcharge"]).to eq(187.2)
end
end
end
context "when the owning organisation is an LA" do
let(:organisation) { FactoryBot.create(:organisation, provider_type: "LA") }
context "when the owning organisation is a LA" do
before { case_log.owning_organisation.update!(provider_type: "LA") }
context "when the rent type is intermediate rent and supported housing" do
it "correctly derives and saves lettype" do
@ -1405,6 +1390,7 @@ RSpec.describe CaseLog do
end
it "correctly derives and saves prevten" do
case_log.managing_organisation.update!({ provider_type: "PRP" })
case_log.update!({ needstype: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select prevten from case_logs where id=#{case_log.id}").to_a[0]

36
spec/models/validations/financial_validations_spec.rb

@ -201,12 +201,11 @@ RSpec.describe Validations::FinancialValidations do
end
end
context "when the landlord is this landlord" do
context "when the owning organisation is a private registered provider" do
before { record.owning_organisation.provider_type = 2 }
context "when needstype is general needs" do
before do
record.needstype = 1
record.landlord = 1
end
before { record.needstype = 1 }
[{
period: { label: "weekly", value: 1 },
@ -249,7 +248,7 @@ RSpec.describe Validations::FinancialValidations do
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.this_landlord.general_needs"))
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.general_needs"))
end
end
@ -300,10 +299,7 @@ RSpec.describe Validations::FinancialValidations do
end
context "when needstype is supported housing" do
before do
record.needstype = 2
record.landlord = 1
end
before { record.needstype = 2 }
[{
period: { label: "weekly", value: 1 },
@ -346,7 +342,7 @@ RSpec.describe Validations::FinancialValidations do
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.this_landlord.supported_housing"))
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.supported_housing"))
end
end
@ -397,12 +393,11 @@ RSpec.describe Validations::FinancialValidations do
end
end
context "when the landlord is another RP" do
context "when the owning organisation is a local authority" do
before { record.owning_organisation.provider_type = 1 }
context "when needstype is general needs" do
before do
record.needstype = 1
record.landlord = 2
end
before { record.needstype = 1 }
[{
period: { label: "weekly", value: 1 },
@ -445,7 +440,7 @@ RSpec.describe Validations::FinancialValidations do
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.other_landlord.general_needs"))
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.general_needs"))
end
end
@ -496,10 +491,7 @@ RSpec.describe Validations::FinancialValidations do
end
context "when needstype is supported housing" do
before do
record.needstype = 2
record.landlord = 2
end
before { record.needstype = 2 }
[{
period: { label: "weekly", value: 1 },
@ -542,7 +534,7 @@ RSpec.describe Validations::FinancialValidations do
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.other_landlord.supported_housing"))
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.supported_housing"))
end
end

16
spec/models/validations/household_validations_spec.rb

@ -4,7 +4,7 @@ RSpec.describe Validations::HouseholdValidations do
subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:record) { FactoryBot.create(:case_log, :same_landlord) }
let(:record) { FactoryBot.create(:case_log) }
describe "reasonable preference validations" do
context "when reasonable preference is homeless" do
@ -197,8 +197,8 @@ RSpec.describe Validations::HouseholdValidations do
.to be_empty
end
it "cannot have `this landlord` as landlord and Housing situation before this letting cannot be LA general needs" do
record.landlord = 1
it "cannot have a PRP as landlord and Housing situation before this letting cannot be LA general needs" do
record.owning_organisation.provider_type = "PRP"
record.prevten = 30
record.referral = 1
household_validator.validate_referral(record)
@ -217,17 +217,17 @@ RSpec.describe Validations::HouseholdValidations do
end
context "when referral is nominated by a local housing authority" do
it "cannot have `other landlord`" do
record.landlord = 2
it "cannot have a local authority" do
record.owning_organisation.provider_type = "LA"
record.referral = 3
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match(I18n.t("validations.household.referral.prp.local_housing_referral")))
end
it "can have `this landlord`" do
it "can have a private registered provider" do
record.owning_organisation.provider_type = "PRP"
record.referral = 3
record.landlord = 1
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to be_empty
@ -654,6 +654,7 @@ RSpec.describe Validations::HouseholdValidations do
end
it "can be non internal transfer" do
record.owning_organisation.provider_type = "PRP"
record.homeless = 0
record.referral = 3
household_validator.validate_referral(record)
@ -674,6 +675,7 @@ RSpec.describe Validations::HouseholdValidations do
end
it "can be non internal transfer" do
record.owning_organisation.provider_type = "PRP"
record.referral = 3
record.homeless = 1
household_validator.validate_referral(record)

Loading…
Cancel
Save