Browse Source

separate out shared ownership leasehold charge into separate question but same variable

pull/3022/head
Carolyn 1 month ago
parent
commit
5ebc20687e
  1. 14
      app/models/form/sales/pages/leasehold_charges.rb
  2. 13
      app/models/form/sales/pages/service_charge.rb
  3. 16
      app/models/form/sales/questions/has_leasehold_charges.rb
  4. 27
      app/models/form/sales/questions/has_service_charge.rb
  5. 16
      app/models/form/sales/questions/leasehold_charges.rb
  6. 15
      app/models/form/sales/questions/service_charge.rb
  7. 2
      app/models/form/sales/subsections/shared_ownership_initial_purchase.rb
  8. 26
      config/locales/forms/2025/sales/sale_information.en.yml
  9. 29
      spec/models/form/sales/pages/service_charge_spec.rb
  10. 49
      spec/models/form/sales/questions/has_service_charge_spec.rb
  11. 37
      spec/models/form/sales/questions/service_charge_spec.rb
  12. 2
      spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb

14
app/models/form/sales/pages/leasehold_charges.rb

@ -2,19 +2,7 @@ class Form::Sales::Pages::LeaseholdCharges < ::Form::Page
def initialize(id, hsh, subsection, ownershipsch:) def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection) super(id, hsh, subsection)
@ownershipsch = ownershipsch @ownershipsch = ownershipsch
end @copy_key = "sales.sale_information.leaseholdcharges"
def copy_key
if form.start_year_2025_or_later?
case @ownershipsch
when 1
"sales.sale_information.leaseholdcharges.shared_ownership"
when 2
"sales.sale_information.leaseholdcharges.discounted_ownership"
end
else
"sales.sale_information.leaseholdcharges"
end
end end
def questions def questions

13
app/models/form/sales/pages/service_charge.rb

@ -0,0 +1,13 @@
class Form::Sales::Pages::ServiceCharge < ::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),
Form::Sales::Questions::ServiceCharge.new(nil, nil, self),
]
end
end

16
app/models/form/sales/questions/has_leasehold_charges.rb

@ -15,22 +15,10 @@ class Form::Sales::Questions::HasLeaseholdCharges < ::Form::Question
], ],
} }
@ownershipsch = ownershipsch @ownershipsch = ownershipsch
@copy_key = "sales.sale_information.leaseholdcharges.has_mscharge"
@question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch]
end end
def copy_key
if form.start_year_2025_or_later?
case @ownershipsch
when 1
"sales.sale_information.leaseholdcharges.shared_ownership.has_mscharge"
when 2
"sales.sale_information.leaseholdcharges.discounted_ownership.has_mscharge"
end
else
"sales.sale_information.leaseholdcharges.has_mscharge"
end
end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"0" => { "value" => "No" }, "0" => { "value" => "No" },
@ -38,6 +26,6 @@ class Form::Sales::Questions::HasLeaseholdCharges < ::Form::Question
QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = {
2024 => { 1 => 99, 2 => 110, 3 => 117 }, 2024 => { 1 => 99, 2 => 110, 3 => 117 },
2025 => { 1 => 88, 2 => 111 }, 2025 => { 2 => 111 },
}.freeze }.freeze
end end

27
app/models/form/sales/questions/has_service_charge.rb

@ -0,0 +1,27 @@
class Form::Sales::Questions::HasServiceCharge < ::Form::Question
def initialize(id, hsh, subsection)
super
@id = "has_mscharge"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"mscharge" => [1],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"has_mscharge" => 1,
},
],
}
@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]
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"0" => { "value" => "No" },
}.freeze
QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze
end

16
app/models/form/sales/questions/leasehold_charges.rb

@ -7,26 +7,14 @@ class Form::Sales::Questions::LeaseholdCharges < ::Form::Question
@step = 0.01 @step = 0.01
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@copy_key = "sales.sale_information.leaseholdcharges.mscharge"
@ownershipsch = ownershipsch @ownershipsch = ownershipsch
@question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch]
end end
def copy_key
if form.start_year_2025_or_later?
case @ownershipsch
when 1
"sales.sale_information.leaseholdcharges.shared_ownership.mscharge"
when 2
"sales.sale_information.leaseholdcharges.discounted_ownership.mscharge"
end
else
"sales.sale_information.leaseholdcharges.mscharge"
end
end
QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = {
2023 => { 1 => 98, 2 => 109, 3 => 117 }, 2023 => { 1 => 98, 2 => 109, 3 => 117 },
2024 => { 1 => 99, 2 => 110, 3 => 117 }, 2024 => { 1 => 99, 2 => 110, 3 => 117 },
2025 => { 1 => 88, 2 => 111 }, 2025 => { 2 => 111 },
}.freeze }.freeze
end end

15
app/models/form/sales/questions/service_charge.rb

@ -0,0 +1,15 @@
class Form::Sales::Questions::ServiceCharge < ::Form::Question
def initialize(id, hsh, subsection)
super
@id = "mscharge"
@type = "numeric"
@min = 1
@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]
end
QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze
end

2
app/models/form/sales/subsections/shared_ownership_initial_purchase.rb

@ -37,7 +37,7 @@ class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsect
Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true), Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true),
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::ServiceCharge.new("service_charge", nil, self),
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self),
Form::Sales::Pages::EstateManagementFee.new("estate_management_fee", nil, self), Form::Sales::Pages::EstateManagementFee.new("estate_management_fee", nil, self),
].compact ].compact

26
config/locales/forms/2025/sales/sale_information.en.yml

@ -246,19 +246,6 @@ en:
question_text: "What is the basic monthly rent after staircasing?" question_text: "What is the basic monthly rent after staircasing?"
leaseholdcharges: leaseholdcharges:
shared_ownership:
page_header: ""
has_mscharge:
check_answer_label: "Property service charges"
check_answer_prompt: "Enter service charges if any"
hint_text: "This includes any charges for day-to-day maintenance and repairs, building insurance, and any contributions to a sinking or reserved fund. It does not include estate management fees."
question_text: "Does the property have any service charges?"
mscharge:
check_answer_label: "Monthly leasehold charges"
check_answer_prompt: ""
hint_text: ""
question_text: "Enter the total monthly charge"
discounted_ownership:
page_header: "" page_header: ""
has_mscharge: has_mscharge:
check_answer_label: "Property leasehold charges" check_answer_label: "Property leasehold charges"
@ -271,6 +258,19 @@ en:
hint_text: "" hint_text: ""
question_text: "Enter the total monthly charge" question_text: "Enter the total monthly charge"
servicecharges:
page_header: ""
has_servicecharge:
check_answer_label: "Property service charges"
check_answer_prompt: "Enter service charges if any"
hint_text: "This includes any charges for day-to-day maintenance and repairs, building insurance, and any contributions to a sinking or reserved fund. It does not include estate management fees."
question_text: "Does the property have any service charges?"
servicecharge:
check_answer_label: "Monthly service charges"
check_answer_prompt: ""
hint_text: ""
question_text: "Enter the total monthly charge"
purchase_price: purchase_price:
discounted_ownership: discounted_ownership:
page_header: "About the price of the property" page_header: "About the price of the property"

29
spec/models/form/sales/pages/service_charge_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::ServiceCharge, 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(2023, 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 eq(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

49
spec/models/form/sales/questions/has_service_charge_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::HasServiceCharge, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
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:)) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("has_mscharge")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?(nil)).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "No" },
"1" => { "value" => "Yes" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"mscharge" => [1],
})
end
it "has correct hidden_in_check_answers for" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"has_mscharge" => 1,
},
],
})
end
end

37
spec/models/form/sales/questions/service_charge_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::ServiceCharge, type: :model do
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)))) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("mscharge")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
end
it "is not marked as derived" do
expect(question.derived?(nil)).to be false
end
it "has the correct width" do
expect(question.width).to be 5
end
it "has the correct min" do
expect(question.min).to be 1
end
it "has the correct prefix" do
expect(question.prefix).to eq("£")
end
end

2
spec/models/form/sales/subsections/shared_ownership_initial_purchase_spec.rb

@ -46,7 +46,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :
deposit_discount_optional deposit_discount_optional
shared_ownership_deposit_value_check shared_ownership_deposit_value_check
monthly_rent monthly_rent
leasehold_charges_shared_ownership service_charge
monthly_charges_shared_ownership_value_check monthly_charges_shared_ownership_value_check
estate_management_fee estate_management_fee
], ],

Loading…
Cancel
Save