diff --git a/app/models/form/sales/pages/service_charge.rb b/app/models/form/sales/pages/service_charge.rb index a0102eda4..e938a3e56 100644 --- a/app/models/form/sales/pages/service_charge.rb +++ b/app/models/form/sales/pages/service_charge.rb @@ -6,8 +6,8 @@ class Form::Sales::Pages::ServiceCharge < ::Form::Page def questions @questions ||= [ - Form::Sales::Questions::HasServiceCharge.new(nil, nil, self), - Form::Sales::Questions::ServiceCharge.new(nil, nil, self), + Form::Sales::Questions::HasServiceCharge.new(nil, nil, self, staircasing: false), + Form::Sales::Questions::ServiceCharge.new(nil, nil, self, staircasing: false), ] end end diff --git a/app/models/form/sales/pages/service_charge_staircasing.rb b/app/models/form/sales/pages/service_charge_staircasing.rb new file mode 100644 index 000000000..4e4f65c9e --- /dev/null +++ b/app/models/form/sales/pages/service_charge_staircasing.rb @@ -0,0 +1,13 @@ +class Form::Sales::Pages::ServiceChargeStaircasing < ::Form::Page + def initialize(id, hsh, subsection) + super + @copy_key = "sales.sale_information.servicecharges" + end + + def questions + @questions ||= [ + Form::Sales::Questions::HasServiceCharge.new(nil, nil, self, staircasing: true), + Form::Sales::Questions::ServiceCharge.new(nil, nil, self, staircasing: true), + ] + end +end diff --git a/app/models/form/sales/questions/has_service_charge.rb b/app/models/form/sales/questions/has_service_charge.rb index 41bf5f809..708c32f0d 100644 --- a/app/models/form/sales/questions/has_service_charge.rb +++ b/app/models/form/sales/questions/has_service_charge.rb @@ -1,6 +1,6 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question - def initialize(id, hsh, subsection) - super + def initialize(id, hsh, subsection, staircasing:) + super(id, hsh, subsection) @id = "has_mscharge" @type = "radio" @answer_options = ANSWER_OPTIONS @@ -15,7 +15,8 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question ], } @copy_key = "sales.sale_information.servicecharges.has_servicecharge" - @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @staircasing = staircasing + @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] end ANSWER_OPTIONS = { @@ -23,5 +24,11 @@ class Form::Sales::Questions::HasServiceCharge < ::Form::Question "0" => { "value" => "No" }, }.freeze - QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze + def question_number_from_year + if @staircasing + { 2026 => 0 }.freeze + else + { 2025 => 88, 2026 => 0 }.freeze + end + end end diff --git a/app/models/form/sales/questions/service_charge.rb b/app/models/form/sales/questions/service_charge.rb index 6b9a76a94..f3aec4a2b 100644 --- a/app/models/form/sales/questions/service_charge.rb +++ b/app/models/form/sales/questions/service_charge.rb @@ -1,16 +1,24 @@ class Form::Sales::Questions::ServiceCharge < ::Form::Question - def initialize(id, hsh, subsection) - super + def initialize(id, hsh, subsection, staircasing:) + super(id, hsh, subsection) @id = "mscharge" @type = "numeric" @min = 1 + @max = 9999.99 @step = 0.01 @width = 5 @prefix = "£" @copy_key = "sales.sale_information.servicecharges.servicecharge" - @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @staircasing = staircasing + @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] @strip_commas = true end - QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze + def question_number_from_year + if @staircasing + { 2026 => 0 }.freeze + else + { 2025 => 88, 2026 => 0 }.freeze + end + end end diff --git a/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb b/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb index cc10ed28c..cfd00e5e1 100644 --- a/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb +++ b/app/models/form/sales/subsections/shared_ownership_staircasing_transaction.rb @@ -25,6 +25,7 @@ class Form::Sales::Subsections::SharedOwnershipStaircasingTransaction < ::Form:: Form::Sales::Pages::Mortgageused.new("staircase_mortgage_used_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::MonthlyRentStaircasingOwned.new(nil, nil, self), Form::Sales::Pages::MonthlyRentStaircasing.new(nil, nil, self), + (Form::Sales::Pages::ServiceChargeStaircasing.new("service_charge_staircasing", nil, self) if form.start_year_2026_or_later?), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), ].compact end diff --git a/app/services/csv/sales_log_csv_service.rb b/app/services/csv/sales_log_csv_service.rb index 07ccad82c..b386b070f 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -249,7 +249,7 @@ module Csv return @attributes unless @user.support? mappings = SUPPORT_ATTRIBUTE_NAME_MAPPINGS - mappings = mappings.merge(SUPPORT_ATTRIBUTE_NAME_MAPPINGS_2025) if @year == 2025 + mappings = mappings.merge(SUPPORT_ATTRIBUTE_NAME_MAPPINGS_2025) if @year >= 2025 @attributes.map do |attribute| mappings[attribute] || attribute.upcase @@ -297,11 +297,10 @@ module Csv end def attribute_mappings - mappings = case @year - when 2024 - ATTRIBUTE_MAPPINGS.merge(ATTRIBUTE_MAPPINGS_2024) - when 2025 + mappings = if @year >= 2025 ATTRIBUTE_MAPPINGS.merge(ATTRIBUTE_MAPPINGS_2024).merge(ATTRIBUTE_MAPPINGS_2025) + elsif @year == 2024 + ATTRIBUTE_MAPPINGS.merge(ATTRIBUTE_MAPPINGS_2024) else ATTRIBUTE_MAPPINGS end @@ -348,6 +347,8 @@ module Csv %w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo] when 2025 %w[id status duplicate_set_id created_at created_by_id updated_at updated_by_id creation_method bulk_upload_id] + when 2026 + %w[id status duplicate_set_id created_at created_by_id updated_at updated_by_id creation_method bulk_upload_id] else %w[id status duplicate_set_id created_at updated_at collection_start_year creation_method bulk_upload_id is_dpo] end diff --git a/spec/models/form/sales/pages/service_charge_staircasing_spec.rb b/spec/models/form/sales/pages/service_charge_staircasing_spec.rb new file mode 100644 index 000000000..a29df7b82 --- /dev/null +++ b/spec/models/form/sales/pages/service_charge_staircasing_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::ServiceChargeStaircasing, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2026, 4, 1))) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[has_mscharge mscharge]) + end + + it "has the correct id" do + expect(page.id).to be_nil + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end +end diff --git a/spec/models/form/sales/questions/has_service_charge_spec.rb b/spec/models/form/sales/questions/has_service_charge_spec.rb index bf0bd9d25..d64609bb0 100644 --- a/spec/models/form/sales/questions/has_service_charge_spec.rb +++ b/spec/models/form/sales/questions/has_service_charge_spec.rb @@ -1,12 +1,14 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::HasServiceCharge, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, staircasing:) } - let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 4)) } let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership", form:)) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:page) { instance_double(Form::Page, subsection:) } + let(:start_date) { Time.utc(2025, 5, 1) } + let(:staircasing) { false } it "has correct page" do expect(question.page).to eq(page) @@ -46,4 +48,44 @@ RSpec.describe Form::Sales::Questions::HasServiceCharge, type: :model do ], }) end + + context "with 2025/26 form" do + let(:start_date) { Time.utc(2025, 4, 1) } + + before do + allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true) + end + + context "when not staircasing" do + let(:staircasing) { false } + + it "has the correct question number" do + expect(question.question_number).to eq(88) + end + end + end + + context "with 2026/27 form" do + let(:start_date) { Time.utc(2026, 4, 1) } + + before do + allow(subsection.form).to receive(:start_year_2026_or_later?).and_return(true) + end + + context "when staircasing" do + let(:staircasing) { true } + + it "has the correct question number" do + expect(question.question_number).to eq(0) + end + end + + context "when not staircasing" do + let(:staircasing) { false } + + it "has the correct question number" do + expect(question.question_number).to eq(0) + end + end + end end diff --git a/spec/models/form/sales/questions/service_charge_spec.rb b/spec/models/form/sales/questions/service_charge_spec.rb index 56dee01cf..21104d2b5 100644 --- a/spec/models/form/sales/questions/service_charge_spec.rb +++ b/spec/models/form/sales/questions/service_charge_spec.rb @@ -1,11 +1,14 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::ServiceCharge, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, staircasing:) } let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:page) { instance_double(Form::Page, subsection:) } + let(:start_date) { Time.utc(2023, 4, 1) } + let(:staircasing) { false } it "has correct page" do expect(question.page).to eq(page) @@ -34,4 +37,44 @@ RSpec.describe Form::Sales::Questions::ServiceCharge, type: :model do it "has the correct prefix" do expect(question.prefix).to eq("£") end + + context "with 2025/26 form" do + let(:start_date) { Time.utc(2025, 4, 1) } + + before do + allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true) + end + + context "when not staircasing" do + let(:staircasing) { false } + + it "has the correct question number" do + expect(question.question_number).to eq(88) + end + end + end + + context "with 2026/27 form" do + let(:start_date) { Time.utc(2026, 4, 1) } + + before do + allow(subsection.form).to receive(:start_year_2026_or_later?).and_return(true) + end + + context "when staircasing" do + let(:staircasing) { true } + + it "has the correct question number" do + expect(question.question_number).to eq(0) + end + end + + context "when not staircasing" do + let(:staircasing) { false } + + it "has the correct question number" do + expect(question.question_number).to eq(0) + end + end + end end diff --git a/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb b/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb new file mode 100644 index 000000000..3efe482d8 --- /dev/null +++ b/spec/models/form/sales/subsections/shared_ownership_staircasing_transaction_spec.rb @@ -0,0 +1,85 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Subsections::SharedOwnershipStaircasingTransaction, type: :model do + subject(:shared_ownership_staircasing_transaction) { described_class.new(nil, nil, section) } + + let(:form) { instance_double(Form, start_year_2026_or_later?: false) } + let(:section) { instance_double(Form::Sales::Sections::SaleInformation, form:) } + + it "has correct section" do + expect(shared_ownership_staircasing_transaction.section).to eq(section) + end + + it "has the correct depends_on" do + expect(shared_ownership_staircasing_transaction.depends_on).to eq([{ "ownershipsch" => 1, "setup_completed?" => true, "staircase" => 1 }]) + end + + it "has the correct id" do + expect(shared_ownership_staircasing_transaction.id).to eq("shared_ownership_staircasing_transaction") + end + + it "has the correct label" do + expect(shared_ownership_staircasing_transaction.label).to eq("Shared ownership - staircasing transaction") + end + + it "has the correct copy key" do + expect(shared_ownership_staircasing_transaction.copy_key).to eq("sale_information") + end + + context "when the start year is 2025" do + let(:form) { instance_double(Form, start_year_2025_or_later?: true, start_year_2026_or_later?: false, start_date: Time.utc(2025, 4, 1)) } + + it "has correct pages" do + expect(shared_ownership_staircasing_transaction.pages.map(&:id)).to eq( + %w[ + about_staircasing_joint_purchase + about_staircasing_not_joint_purchase + staircase_sale + staircase_bought_value_check + staircase_owned_value_check_joint_purchase + staircase_owned_value_check_not_joint_purchase + staircase_first_time + staircase_previous + staircase_initial_date + value_shared_ownership_staircase + about_price_shared_ownership_value_check_staircasing + staircase_equity + shared_ownership_equity_value_check_staircasing + staircase_mortgage_used_shared_ownership + monthly_rent_staircasing_owned + monthly_rent_staircasing + monthly_charges_shared_ownership_value_check + ], + ) + end + end + + context "when the start year is 2026" do + let(:form) { instance_double(Form, start_year_2025_or_later?: true, start_year_2026_or_later?: true, start_date: Time.utc(2026, 4, 1)) } + + it "has correct pages" do + expect(shared_ownership_staircasing_transaction.pages.map(&:id)).to eq( + %w[ + about_staircasing_joint_purchase + about_staircasing_not_joint_purchase + staircase_sale + staircase_bought_value_check + staircase_owned_value_check_joint_purchase + staircase_owned_value_check_not_joint_purchase + staircase_first_time + staircase_previous + staircase_initial_date + value_shared_ownership_staircase + about_price_shared_ownership_value_check_staircasing + staircase_equity + shared_ownership_equity_value_check_staircasing + staircase_mortgage_used_shared_ownership + monthly_rent_staircasing_owned + monthly_rent_staircasing + service_charge_staircasing + monthly_charges_shared_ownership_value_check + ], + ) + end + end +end