diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 6d50bb5ff..90d4e9db2 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -8,6 +8,7 @@ module DerivedVariables::LettingsLogVariables 3 => 3, # "Rent to Buy" => "Intermediate Rent" 4 => 3, # "London Living Rent" => "Intermediate Rent" 5 => 3, # "Other intermediate rent product" => "Intermediate Rent" + 6 => 4, # "Specified accommodation - exempt accommodation, managed properties, refuges and local authority hostels" => "Specified accommodation" }.freeze UNITLETAS_MAPPING = { @@ -17,6 +18,7 @@ module DerivedVariables::LettingsLogVariables 3 => 6, # "Rent to Buy" => "Rent to Buy basis" 4 => 7, # "London Living Rent" => "London Living Rent basis" 5 => 8, # "Other intermediate rent product" => "Another Intermediate Rent basis" + 6 => 9, # "Specified accommodation - exempt accommodation, managed properties, refuges and local authority hostels" => "Specified accommodation - exempt accommodation, manged properties, refuges and local authority hostels" }.freeze RENTTYPE_DETAIL_MAPPING = { @@ -26,6 +28,7 @@ module DerivedVariables::LettingsLogVariables 3 => 4, 4 => 5, 5 => 6, + 6 => 7, }.freeze def set_derived_fields! diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index c8505b310..2c523da47 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -146,7 +146,7 @@ class LettingsLog < Log AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze OPTIONAL_FIELDS = %w[tenancycode propcode chcharge].freeze - RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze + RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent", 4 => "Specified accommodation" }.freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze @@ -158,6 +158,7 @@ class LettingsLog < Log rent_to_buy: 3, london_living_rent: 4, other_intermediate_rent_product: 5, + specified_accommodation: 6, }.freeze def form @@ -826,6 +827,12 @@ private elsif is_general_needs? owning_organisation[:provider_type] == "PRP" ? 9 : 11 end + when "Specified accommodation" + if is_supported_housing? + owning_organisation[:provider_type] == "PRP" ? 14 : 16 + elsif is_general_needs? + owning_organisation[:provider_type] == "PRP" ? 13 : 15 + end end end diff --git a/spec/models/lettings_log_derived_fields_spec.rb b/spec/models/lettings_log_derived_fields_spec.rb index aae1396d7..d315db51e 100644 --- a/spec/models/lettings_log_derived_fields_spec.rb +++ b/spec/models/lettings_log_derived_fields_spec.rb @@ -187,6 +187,18 @@ RSpec.describe LettingsLog, type: :model do needstype: 1, expected_lettype: 1, }, + { + context: "when the rent type is Specified accommodation and supported housing", + rent_type: 6, + needstype: 2, + expected_lettype: 14, + }, + { + context: "when the rent type is Specified accommodation and general needs housing", + rent_type: 6, + needstype: 1, + expected_lettype: 13, + }, ].each do |test_case| context test_case[:context] do it "correctly derives lettype" do @@ -953,6 +965,11 @@ RSpec.describe LettingsLog, type: :model do log.rent_type = 5 expect { log.set_derived_fields! }.to change(log, :renttype).to 3 end + + it "when rent_type is Specified accommodation derives renttype as Specified accommodation" do + log.rent_type = 6 + expect { log.set_derived_fields! }.to change(log, :renttype).to 4 + end end describe "variables dependent on whether a letting is a renewal" do @@ -1168,6 +1185,25 @@ RSpec.describe LettingsLog, type: :model do expect { persisted_renewal_lettings_log.update!(renewal: 0) }.to change(persisted_renewal_lettings_log, :unitletas).from(expected_unitletas).to nil end end + + context "when rent_type is Specified accommodation " do + let(:rent_type) { 6 } + let(:expected_unitletas) { 9 } + + before do + Timecop.freeze(Time.zone.local(2025, 5, 5)) + end + + it "derives the most recent let type as London Living Rent basis if it is a renewal" do + log.assign_attributes(renewal: 1, rent_type:) + + expect { log.set_derived_fields! }.to change(log, :unitletas).to expected_unitletas + end + + it "clears the most recent let type if it is not a renewal" do + expect { persisted_renewal_lettings_log.update!(renewal: 0) }.to change(persisted_renewal_lettings_log, :unitletas).from(expected_unitletas).to nil + end + end end end end