diff --git a/app/models/form/sales/questions/management_fee.rb b/app/models/form/sales/questions/management_fee.rb index af7ff574f..6ca114981 100644 --- a/app/models/form/sales/questions/management_fee.rb +++ b/app/models/form/sales/questions/management_fee.rb @@ -5,6 +5,7 @@ class Form::Sales::Questions::ManagementFee < ::Form::Question @copy_key = "sales.sale_information.management_fee.management_fee" @type = "numeric" @min = 1 + @max = form.start_year_2025_or_later? ? 9_999 : nil @step = 0.01 @width = 5 @prefix = "£" diff --git a/app/models/form/sales/questions/monthly_rent_before_staircasing.rb b/app/models/form/sales/questions/monthly_rent_before_staircasing.rb index 042e2be32..bf101e993 100644 --- a/app/models/form/sales/questions/monthly_rent_before_staircasing.rb +++ b/app/models/form/sales/questions/monthly_rent_before_staircasing.rb @@ -5,6 +5,7 @@ class Form::Sales::Questions::MonthlyRentBeforeStaircasing < ::Form::Question @copy_key = "sales.sale_information.mrent_staircasing.prestaircasing" @type = "numeric" @min = 0 + @max = form.start_year_2025_or_later? ? 9_999 : nil @step = 0.01 @width = 5 @prefix = "£" diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index 81549c011..2a11b882d 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -4,6 +4,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question @id = "mortgage" @type = "numeric" @min = 1 + @max = form.start_year_2025_or_later? ? 999_999 : nil @step = 1 @width = 5 @prefix = "£" diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb index 8a919b55f..010dfa99a 100644 --- a/app/models/form/sales/questions/purchase_price.rb +++ b/app/models/form/sales/questions/purchase_price.rb @@ -4,6 +4,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question @id = "value" @type = "numeric" @min = form.start_year_2026_or_later? ? 15_000 : 0 + @max = form.start_year_2025_or_later? ? 999_999 : nil @step = form.start_year_2026_or_later? ? 1 : 0.01 # 0.01 was a mistake that was fixed in 2026 @width = 5 @prefix = "£" diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb index 0884a3fb6..0521c3705 100644 --- a/app/models/form/sales/questions/value.rb +++ b/app/models/form/sales/questions/value.rb @@ -5,6 +5,7 @@ class Form::Sales::Questions::Value < ::Form::Question @copy_key = form.start_year_2025_or_later? ? "sales.sale_information.value.#{page.id}" : "sales.sale_information.value" @type = "numeric" @min = form.start_year_2026_or_later? ? 15_000 : 0 + @max = form.start_year_2025_or_later? ? 999_999 : nil @step = 1 @width = 10 @prefix = "£" diff --git a/lib/tasks/correct_values_missing_max_for_2025_or_later_sales_logs.rake b/lib/tasks/correct_values_missing_max_for_2025_or_later_sales_logs.rake new file mode 100644 index 000000000..87d683c97 --- /dev/null +++ b/lib/tasks/correct_values_missing_max_for_2025_or_later_sales_logs.rake @@ -0,0 +1,16 @@ +desc "Clears mortgage, purchase price (the 'value' field), monthly rent before staircasing and management fee values for sales logs in the database if they are over their new max" +task correct_values_missing_max_for_2025_or_later_sales_logs: :environment do + mortgage_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("mortgage > 999999") + value_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("value > 999999") + mrentprestaircasing_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("mrentprestaircasing > 9999") + management_fee_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("management_fee > 9999") + all_incorrect_logs = (mortgage_incorrect_logs + value_incorrect_logs + mrentprestaircasing_incorrect_logs + management_fee_incorrect_logs).uniq + puts "Correcting #{all_incorrect_logs.count} sales logs, #{all_incorrect_logs.map(&:id)}" + + mortgage_incorrect_logs.update!(mortgage: nil) + value_incorrect_logs.update!(value: nil) + mrentprestaircasing_incorrect_logs.update!(mrentprestaircasing: nil) + management_fee_incorrect_logs.update!(management_fee: nil) + + puts "Done" +end diff --git a/spec/models/form/sales/pages/monthly_rent_staircasing_owned_spec.rb b/spec/models/form/sales/pages/monthly_rent_staircasing_owned_spec.rb index 21f0e0ee6..2761e5f76 100644 --- a/spec/models/form/sales/pages/monthly_rent_staircasing_owned_spec.rb +++ b/spec/models/form/sales/pages/monthly_rent_staircasing_owned_spec.rb @@ -1,11 +1,13 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::MonthlyRentStaircasingOwned, type: :model do + include CollectionTimeHelper + 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(2025, 4, 1))) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_date, start_year_2025_or_later?: true)) } it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/sales/pages/monthly_rent_staircasing_spec.rb b/spec/models/form/sales/pages/monthly_rent_staircasing_spec.rb index 347e105fd..21e68ea64 100644 --- a/spec/models/form/sales/pages/monthly_rent_staircasing_spec.rb +++ b/spec/models/form/sales/pages/monthly_rent_staircasing_spec.rb @@ -1,11 +1,13 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::MonthlyRentStaircasing, type: :model do + include CollectionTimeHelper + 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(2025, 4, 1))) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_year, start_year_2025_or_later?: true)) } it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/sales/pages/mortgage_amount_spec.rb b/spec/models/form/sales/pages/mortgage_amount_spec.rb index 8127dfb2d..045d8b1dc 100644 --- a/spec/models/form/sales/pages/mortgage_amount_spec.rb +++ b/spec/models/form/sales/pages/mortgage_amount_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::MortgageAmount, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false)) } + let(:subsection) { instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: true)) } it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb b/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb index e26221554..00f7d1f4e 100644 --- a/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb +++ b/spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::PurchasePriceOutrightOwnership, type: :model let(:page_id) { "purchase_price" } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, id: "discounted_ownership_scheme", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false)) } + let(:subsection) { instance_double(Form::Subsection, id: "discounted_ownership_scheme", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: false)) } it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/sales/pages/purchase_price_spec.rb b/spec/models/form/sales/pages/purchase_price_spec.rb index 8ceb58f4a..4b74bbd4c 100644 --- a/spec/models/form/sales/pages/purchase_price_spec.rb +++ b/spec/models/form/sales/pages/purchase_price_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Form::Sales::Pages::PurchasePrice, type: :model do let(:subsection) { instance_double(Form::Subsection) } before do - allow(subsection).to receive_messages(form: instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false), id: "discounted_ownership_scheme") + allow(subsection).to receive_messages(form: instance_double(Form, start_year_2024_or_later?: true, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: false), id: "discounted_ownership_scheme") end it "has correct subsection" do diff --git a/spec/models/form/sales/pages/value_shared_ownership_spec.rb b/spec/models/form/sales/pages/value_shared_ownership_spec.rb index e7e709d28..a8a1db327 100644 --- a/spec/models/form/sales/pages/value_shared_ownership_spec.rb +++ b/spec/models/form/sales/pages/value_shared_ownership_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::ValueSharedOwnership, type: :model do let(:page_id) { "value_shared_ownership" } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false), id: "shared_ownership") } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: false), id: "shared_ownership") } before do allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false) diff --git a/spec/models/form/sales/questions/monthly_rent_before_staircasing_spec.rb b/spec/models/form/sales/questions/monthly_rent_before_staircasing_spec.rb index 8d7d864a8..8ec7b1824 100644 --- a/spec/models/form/sales/questions/monthly_rent_before_staircasing_spec.rb +++ b/spec/models/form/sales/questions/monthly_rent_before_staircasing_spec.rb @@ -1,11 +1,14 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::MonthlyRentBeforeStaircasing, type: :model do + include CollectionTimeHelper + subject(:question) { described_class.new(question_id, question_definition, page) } 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(:start_year_2025_or_later?) { true } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_date, start_year_2025_or_later?: start_year_2025_or_later?))) } it "has correct page" do expect(question.page).to eq(page) @@ -34,4 +37,8 @@ RSpec.describe Form::Sales::Questions::MonthlyRentBeforeStaircasing, type: :mode it "has correct min" do expect(question.min).to eq(0) end + + it "has correct max" do + expect(question.max).to eq(9_999) + end end diff --git a/spec/models/form/sales/questions/mortgage_amount_spec.rb b/spec/models/form/sales/questions/mortgage_amount_spec.rb index 12da4bc1f..064dead90 100644 --- a/spec/models/form/sales/questions/mortgage_amount_spec.rb +++ b/spec/models/form/sales/questions/mortgage_amount_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false))) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: true))) } it "has correct page" do expect(question.page).to be(page) @@ -35,6 +35,10 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do expect(question.min).to be(1) end + it "has correct max" do + expect(question.max).to eq(999_999) + end + context "when the mortgage is not used" do let(:log) { build(:sales_log, :completed, mortgageused: 2, deposit: nil) } diff --git a/spec/models/form/sales/questions/purchase_price_spec.rb b/spec/models/form/sales/questions/purchase_price_spec.rb index 47081edb4..083baf4da 100644 --- a/spec/models/form/sales/questions/purchase_price_spec.rb +++ b/spec/models/form/sales/questions/purchase_price_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do let(:question_definition) { nil } let(:start_year) { current_collection_start_year } let(:start_year_2026_or_later?) { false } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?))) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?, start_year_2025_or_later?: true))) } it "has correct page" do expect(question.page).to eq(page) @@ -65,6 +65,10 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do it "has correct min" do expect(question.min).to eq(0) end + + it "has correct max" do + expect(question.max).to eq(999_999) + end end context "with year 2026", metadata: { year: 26 } do @@ -74,5 +78,9 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do it "has correct min" do expect(question.min).to eq(15_000) end + + it "has correct max" do + expect(question.max).to eq(999_999) + end end end diff --git a/spec/models/form/sales/questions/value_spec.rb b/spec/models/form/sales/questions/value_spec.rb index 952b02e7c..ca63f89f5 100644 --- a/spec/models/form/sales/questions/value_spec.rb +++ b/spec/models/form/sales/questions/value_spec.rb @@ -9,11 +9,7 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do let(:question_definition) { nil } let(:start_year) { current_collection_start_year } let(:start_year_2026_or_later?) { false } - let(:page) { instance_double(Form::Page, id: "value_shared_ownership", subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?), id: "shared_ownership")) } - - before do - allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false) - end + let(:page) { instance_double(Form::Page, id: "value_shared_ownership", subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?, start_year_2025_or_later?: true), id: "shared_ownership")) } it "has correct page" do expect(question.page).to eq(page) @@ -45,6 +41,10 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do it "has correct min" do expect(question.min).to eq(0) end + + it "has correct max" do + expect(question.max).to eq(999_999) + end end context "with year 2026", metadata: { year: 26 } do @@ -54,5 +54,9 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do it "has correct min" do expect(question.min).to eq(15_000) end + + it "has correct max" do + expect(question.max).to eq(999_999) + end end end