Browse Source
* Add shared ownership initial purchase subsection * Display correct subsection based on year * Update some content * Update LivingBeforePurchase routing * Update routing and check for page existence in guidance * Add management fee questions * Only check the subsections relevant to the form * Update content * Update financial calculations textpull/2804/head^2
kosiakkatrina
2 months ago
committed by
GitHub
15 changed files with 326 additions and 32 deletions
@ -0,0 +1,13 @@
|
||||
class Form::Sales::Pages::EstateManagementFee < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@copy_key = "sales.sale_information.management_fee" |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::HasManagementFee.new(nil, nil, self), |
||||
Form::Sales::Questions::ManagementFee.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,24 @@
|
||||
class Form::Sales::Questions::HasManagementFee < ::Form::Question |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "has_management_fee" |
||||
@copy_key = "sales.sale_information.management_fee.has_management_fee" |
||||
@type = "radio" |
||||
@answer_options = ANSWER_OPTIONS |
||||
@conditional_for = { |
||||
"management_fee" => [1], |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"has_management_fee" => 1, |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
|
||||
ANSWER_OPTIONS = { |
||||
"1" => { "value" => "Yes" }, |
||||
"0" => { "value" => "No" }, |
||||
}.freeze |
||||
end |
@ -0,0 +1,12 @@
|
||||
class Form::Sales::Questions::ManagementFee < ::Form::Question |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "management_fee" |
||||
@copy_key = "sales.sale_information.management_fee.management_fee" |
||||
@type = "numeric" |
||||
@min = 1 |
||||
@step = 0.01 |
||||
@width = 5 |
||||
@prefix = "£" |
||||
end |
||||
end |
@ -0,0 +1,48 @@
|
||||
class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsection |
||||
def initialize(id, hsh, section) |
||||
super |
||||
@id = "shared_ownership_initial_purchase" |
||||
@label = "Shared ownership - initial purchase" |
||||
@depends_on = [{ "ownershipsch" => 1, "setup_completed?" => true, "staircase" => 2 }] |
||||
end |
||||
|
||||
def pages |
||||
@pages ||= [ |
||||
Form::Sales::Pages::Resale.new(nil, nil, self), |
||||
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership_joint_purchase", nil, self, ownershipsch: 1, joint_purchase: true), |
||||
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership", nil, self, ownershipsch: 1, joint_purchase: false), |
||||
Form::Sales::Pages::HandoverDate.new(nil, nil, self), |
||||
Form::Sales::Pages::HandoverDateCheck.new(nil, nil, self), |
||||
Form::Sales::Pages::BuyerPrevious.new("buyer_previous_joint_purchase", nil, self, joint_purchase: true), |
||||
Form::Sales::Pages::BuyerPrevious.new("buyer_previous_not_joint_purchase", nil, self, joint_purchase: false), |
||||
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), |
||||
Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), |
||||
Form::Sales::Pages::PreviousTenure.new(nil, nil, self), |
||||
Form::Sales::Pages::ValueSharedOwnership.new(nil, nil, self), |
||||
Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), |
||||
Form::Sales::Pages::Equity.new(nil, nil, self), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self), |
||||
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_mortgage_amount_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageValueCheck.new("mortgage_amount_mortgage_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::Deposit.new("deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), |
||||
Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true), |
||||
Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true), |
||||
Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), |
||||
Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false), |
||||
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::MonthlyRent.new(nil, nil, self), |
||||
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), |
||||
Form::Sales::Pages::EstateManagementFee.new("estate_management_fee", nil, self), |
||||
].compact |
||||
end |
||||
|
||||
def displayed_in_tasklist?(log) |
||||
log.staircase == 2 && (log.ownershipsch.nil? || log.ownershipsch == 1) |
||||
end |
||||
end |
@ -0,0 +1,8 @@
|
||||
class AddManagementFeeFields < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :sales_logs, bulk: true do |t| |
||||
t.column :has_management_fee, :integer |
||||
t.column :management_fee, :decimal, precision: 10, scale: 2 |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,95 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :model do |
||||
subject(:shared_ownership_initial_purchase) { described_class.new(subsection_id, subsection_definition, section) } |
||||
|
||||
let(:subsection_id) { nil } |
||||
let(:subsection_definition) { nil } |
||||
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } |
||||
|
||||
before do |
||||
allow(section).to receive(:form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) |
||||
end |
||||
|
||||
it "has correct section" do |
||||
expect(shared_ownership_initial_purchase.section).to eq(section) |
||||
end |
||||
|
||||
it "has correct pages" do |
||||
expect(shared_ownership_initial_purchase.pages.map(&:id)).to eq( |
||||
%w[ |
||||
resale |
||||
living_before_purchase_shared_ownership_joint_purchase |
||||
living_before_purchase_shared_ownership |
||||
handover_date |
||||
handover_date_check |
||||
buyer_previous_joint_purchase |
||||
buyer_previous_not_joint_purchase |
||||
previous_bedrooms |
||||
previous_property_type |
||||
shared_ownership_previous_tenure |
||||
value_shared_ownership |
||||
about_price_shared_ownership_value_check |
||||
equity |
||||
shared_ownership_equity_value_check |
||||
mortgage_used_shared_ownership |
||||
mortgage_used_mortgage_value_check |
||||
mortgage_amount_shared_ownership |
||||
shared_ownership_mortgage_amount_value_check |
||||
mortgage_amount_mortgage_value_check |
||||
mortgage_length_shared_ownership |
||||
deposit_shared_ownership |
||||
deposit_shared_ownership_optional |
||||
deposit_joint_purchase_value_check |
||||
deposit_value_check |
||||
deposit_discount |
||||
deposit_discount_optional |
||||
shared_ownership_deposit_value_check |
||||
monthly_rent |
||||
leasehold_charges_shared_ownership |
||||
monthly_charges_shared_ownership_value_check |
||||
estate_management_fee |
||||
], |
||||
) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(shared_ownership_initial_purchase.id).to eq("shared_ownership_initial_purchase") |
||||
end |
||||
|
||||
it "has the correct label" do |
||||
expect(shared_ownership_initial_purchase.label).to eq("Shared ownership - initial purchase") |
||||
end |
||||
|
||||
it "has the correct depends_on" do |
||||
expect(shared_ownership_initial_purchase.depends_on).to eq([ |
||||
{ |
||||
"ownershipsch" => 1, "setup_completed?" => true, "staircase" => 2 |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
context "when it is a shared ownership scheme and not staircase" do |
||||
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1, staircase: 2) } |
||||
|
||||
it "is displayed in tasklist" do |
||||
expect(shared_ownership_initial_purchase.displayed_in_tasklist?(log)).to eq(true) |
||||
end |
||||
end |
||||
|
||||
context "when it is not a shared ownership scheme" do |
||||
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2, staircase: 2) } |
||||
|
||||
it "is displayed in tasklist" do |
||||
expect(shared_ownership_initial_purchase.displayed_in_tasklist?(log)).to eq(false) |
||||
end |
||||
end |
||||
|
||||
context "when it is staircase" do |
||||
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1, staircase: 1) } |
||||
|
||||
it "is displayed in tasklist" do |
||||
expect(shared_ownership_initial_purchase.displayed_in_tasklist?(log)).to eq(false) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue