Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDC-3844 Add rent type response #2900

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/derived_variables/lettings_log_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -26,6 +28,7 @@ module DerivedVariables::LettingsLogVariables
3 => 4,
4 => 5,
5 => 6,
6 => 7,
}.freeze

def set_derived_fields!
Expand Down
21 changes: 20 additions & 1 deletion app/models/form/lettings/questions/previous_let_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def initialize(id, hsh, page)
@id = "unitletas"
@type = "radio"
@check_answers_card_number = 0
@answer_options = form.start_year_2024_or_later? ? ANSWER_OPTIONS_AFTER_2024 : ANSWER_OPTIONS
@answer_options = answer_options
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
end

Expand All @@ -30,5 +30,24 @@ def initialize(id, hsh, page)
"3" => { "value" => "Don’t know" },
}.freeze

ANSWER_OPTIONS_AFTER_2025 = {
"1" => { "value" => "Social rent basis" },
"2" => { "value" => "Affordable rent basis" },
"5" => { "value" => "London Affordable Rent basis" },
"6" => { "value" => "Rent to Buy basis" },
"7" => { "value" => "London Living Rent basis" },
"8" => { "value" => "Another Intermediate Rent basis" },
"9" => { "value" => "Specified accommodation - exempt accommodation, manged properties, refuges and local authority hostels" },
"divider" => { "value" => true },
"3" => { "value" => "Don’t know" },
}.freeze

QUESTION_NUMBER_FROM_YEAR = { 2023 => 16, 2024 => 17 }.freeze

def answer_options
return ANSWER_OPTIONS_AFTER_2025 if form.start_year_2025_or_later?
return ANSWER_OPTIONS_AFTER_2024 if form.start_year_2024_or_later?

ANSWER_OPTIONS
end
end
13 changes: 9 additions & 4 deletions app/models/form/lettings/questions/rent_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@ def initialize(id, hsh, page)
@copy_key = "lettings.setup.rent_type.rent_type"
@type = "radio"
@top_guidance_partial = "rent_type_definitions"
@answer_options = form.start_year_2024_or_later? ? ANSWER_OPTIONS_2024 : ANSWER_OPTIONS
@answer_options = answer_options
@conditional_for = { "irproduct_other" => [5] }
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] if form.start_date.present?
end

ANSWER_OPTIONS = {
"0" => { "value" => "Social Rent" },
"1" => { "value" => "Affordable Rent" },
"2" => { "value" => "London Affordable Rent" },
"4" => { "value" => "London Living Rent" },
"3" => { "value" => "Rent to Buy" },
"0" => { "value" => "Social Rent" },
"4" => { "value" => "London Living Rent" },
"5" => { "value" => "Other intermediate rent product" },
}.freeze

ANSWER_OPTIONS_2024 = {
ANSWER_OPTIONS_2025 = {
"0" => { "value" => "Social Rent" },
"1" => { "value" => "Affordable Rent" },
"2" => { "value" => "London Affordable Rent" },
"3" => { "value" => "Rent to Buy" },
"4" => { "value" => "London Living Rent" },
"5" => { "value" => "Other intermediate rent product" },
"6" => { "value" => "Specified accommodation - exempt accommodation, managed properties, refuges and local authority hostels" },
}.freeze

QUESTION_NUMBER_FROM_YEAR = { 2023 => 6, 2024 => 8 }.freeze

def answer_options
form.start_year_2025_or_later? ? ANSWER_OPTIONS_2025 : ANSWER_OPTIONS
end
end
9 changes: 8 additions & 1 deletion app/models/lettings_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -826,6 +827,12 @@ def get_lettype
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

Expand Down
1 change: 1 addition & 0 deletions spec/models/form/lettings/pages/rent_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
before do
allow(subsection).to receive(:form).and_return(form)
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(false)
end

it "has correct subsection" do
Expand Down
21 changes: 21 additions & 0 deletions spec/models/form/lettings/questions/previous_let_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
end
Expand Down Expand Up @@ -60,4 +61,24 @@
})
end
end

context "with collection year on or after 2025" do
before do
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
end

it "has the correct answer options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Social rent basis" },
"2" => { "value" => "Affordable rent basis" },
"5" => { "value" => "London Affordable Rent basis" },
"6" => { "value" => "Rent to Buy basis" },
"7" => { "value" => "London Living Rent basis" },
"8" => { "value" => "Another Intermediate Rent basis" },
"9" => { "value" => "Specified accommodation - exempt accommodation, manged properties, refuges and local authority hostels" },
"divider" => { "value" => true },
"3" => { "value" => "Don’t know" },
})
end
end
end
9 changes: 5 additions & 4 deletions spec/models/form/lettings/questions/rent_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
before do
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(form).to receive(:start_year_2025_or_later?).and_return(false)
end

it "has correct page" do
Expand All @@ -35,9 +35,9 @@
expect(question.derived?(nil)).to be false
end

context "when 2023" do
context "when 2025" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
end

it "has the correct answer_options" do
Expand All @@ -48,6 +48,7 @@
"3" => { "value" => "Rent to Buy" },
"0" => { "value" => "Social Rent" },
"5" => { "value" => "Other intermediate rent product" },
"6" => { "value" => "Specified accommodation - exempt accommodation, managed properties, refuges and local authority hostels" },
})
end

Expand All @@ -58,7 +59,7 @@

context "when 2024" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(false)
end

it "has the correct answer_options" do
Expand Down
36 changes: 36 additions & 0 deletions spec/models/lettings_log_derived_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@
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
Expand Down Expand Up @@ -953,6 +965,11 @@
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
Expand Down Expand Up @@ -1168,6 +1185,25 @@
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
Loading