Browse Source

Cldc 1547 leasehold charges (#1134)

* Mark subsection as completed if it is not displayed in the tasklist and hide it from the UI

* Add sale_information section

* add sales information subsections

* Cldc 1531 staircasing (#1109)

* Add staircase field to sales_logs table

* Add staircase question and page

* add staircase page to the shared ownership scheme subsection fix file name

* Cldc 1539 previous bedrooms (#1108)

* add frombeds field

* Add previous_bedrooms page and question

* add Previous Bedrooms page to the shared ownership subsection

* Cldc 1532 about staircasing (#1110)

* Add stairboughts and stairowned fields to the database

* Add about staircasing page and questions

* Add about staircasing page to the shared wnership scheme subsection

* Add a space before percent

* Cldc 1546 monthly rent (#1111)

* Add monthly rent column to sales logs table

* Add monthly rent question and page

* Add monthly rent page to the shared ownership scheme subsection

* Cldc 1535 exchange contracts (#1112)

* Add exdate to sales logs table

* Add exchange date page and question

* Add exchange contracts page to the shared ownership subsection

* derive exday, exmonth and exyear, tests and lint

* rebase tests

* Cldc 1538 la nominations (#1115)

* Add la nominations column to sales logs table

* Add La nominations page and questions

* Add la nominations to the shared ownership subsection

* Add accidentally removed files

* Cldc 1545 about the deposit (#1113)

* feat: add question(s) without depends_on behaviour

* feat: separate ids for diff sections

* test: update tests

* test: add tests

* tests: test tweaks

* refactor: linting

* Cldc 1538 la nominations (#1115)

* Add la nominations column to sales logs table

* Add La nominations page and questions

* Add la nominations to the shared ownership subsection

* Add accidentally removed files

* feat: add question(s) without depends_on behaviour

Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>

* Cldc 1533 is resale (#1118)

* feat: add resale question and page

* tests: add new tests

* test: update previous tests

* refactor: linting

* refactor: linting

* Cldc 1576 buyer prp (#1117)

* Add soctenant field to sales logs

* Add buyer previous page and question

* Add buyer previous page to shared ownership scheme subsection

* rebase migrate

* rebase too

* Cldc 1540 about price (#1121)

* add price fields to the sales logs table

* Add about proce questions

* add about proce pages

* Add about price pages to sale information sections

* rebase changes

* happy new year

* Switch the order of sales log sections

* Cldc 1540 fixes (#1130)

* Update order of pages and remove wrong id's

* Add spacing to the hint text

* feat: add page, question, and update db

* Cldc 1521 living before purchase (#1129)

* feat: add new page and question and update db

* test: add and update tests

* feat: reset db

* feat: infer mscharge if mscharge_known == No

* test: add and update tests

* feat: add page, question, and update db

* feat: infer mscharge if mscharge_known == No

* test: add and update tests

* feat: update to main

* test: update tests

* tests: update tests

* faet: move mscharge derivation

Co-authored-by: Kat <katrina@kosiak.co.uk>
Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
pull/1162/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
b9f775fba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/derived_variables/sales_log_variables.rb
  2. 15
      app/models/form/sales/pages/leasehold_charges.rb
  3. 13
      app/models/form/sales/questions/leasehold_charges.rb
  4. 27
      app/models/form/sales/questions/leasehold_charges_known.rb
  5. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  6. 1
      app/models/form/sales/subsections/outright_sale.rb
  7. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  8. 8
      db/migrate/20230103112225_add_mscharge_known_to_sales.rb
  9. 2
      db/schema.rb
  10. 2
      spec/factories/sales_log.rb
  11. 33
      spec/models/form/sales/pages/leasehold_charges_spec.rb
  12. 60
      spec/models/form/sales/questions/leasehold_charges_known_spec.rb
  13. 49
      spec/models/form/sales/questions/leasehold_charges_spec.rb
  14. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  15. 7
      spec/models/form/sales/subsections/outright_sale_spec.rb
  16. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  17. 4
      spec/models/form_handler_spec.rb

3
app/models/derived_variables/sales_log_variables.rb

@ -7,5 +7,8 @@ module DerivedVariables::SalesLogVariables
self.exyear = exdate.year
end
self.deposit = value if outright_sale? && mortgage_not_used?
if mscharge_known.present? && mscharge_known.zero?
self.mscharge = 0
end
end
end

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

@ -0,0 +1,15 @@
class Form::Sales::Pages::LeaseholdCharges < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::LeaseholdChargesKnown.new(nil, nil, self),
Form::Sales::Questions::LeaseholdCharges.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,13 @@
class Form::Sales::Questions::LeaseholdCharges < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mscharge"
@check_answer_label = "Monthly leasehold charges"
@header = "Enter the total monthly charge"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
end
end

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

@ -0,0 +1,27 @@
class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mscharge_known"
@check_answer_label = "Monthly leasehold charges known?"
@header = "Does the property have any monthly leasehold charges?"
@hint_text = "For example, service and management charges"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@conditional_for = {
"mscharge" => [1],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"mscharge_known" => 1,
},
],
}
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"0" => { "value" => "No" },
}.freeze
end

1
app/models/form/sales/subsections/discounted_ownership_scheme.rb

@ -16,6 +16,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self),
]
end

1
app/models/form/sales/subsections/outright_sale.rb

@ -14,6 +14,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self),
Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_outright_sale", nil, self),
]
end

1
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -24,6 +24,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self),
Form::Sales::Pages::DepositValueCheck.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),
]
end

8
db/migrate/20230103112225_add_mscharge_known_to_sales.rb

@ -0,0 +1,8 @@
class AddMschargeKnownToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :mscharge_known, :integer
t.column :mscharge, :decimal, precision: 10, scale: 2
end
end
end

2
db/schema.rb

@ -461,6 +461,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.integer "mortgageused"
t.integer "wchair"
t.integer "armedforcesspouse"
t.integer "mscharge_known"
t.decimal "mscharge", precision: 10, scale: 2
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

2
spec/factories/sales_log.rb

@ -90,6 +90,8 @@ FactoryBot.define do
mortgageused { 1 }
wchair { 1 }
armedforcesspouse { 5 }
mscharge_known { 1 }
mscharge { 100 }
end
end
end

33
spec/models/form/sales/pages/leasehold_charges_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LeaseholdCharges, 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) }
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[mscharge_known mscharge])
end
it "has the correct id" do
expect(page.id).to eq(nil)
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

60
spec/models/form/sales/questions/leasehold_charges_known_spec.rb

@ -0,0 +1,60 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::LeaseholdChargesKnown, 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) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("mscharge_known")
end
it "has the correct header" do
expect(question.header).to eq("Does the property have any monthly leasehold charges?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Monthly leasehold charges known?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).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 the correct hint" do
expect(question.hint_text).to eq("For example, service and management charges")
end
it "has correct hidden_in_check_answers for" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"mscharge_known" => 1,
},
],
})
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::LeaseholdCharges, 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) }
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 header" do
expect(question.header).to eq("Enter the total monthly charge")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Monthly leasehold charges")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
it "has the correct width" do
expect(question.width).to eq(5)
end
it "has the correct min" do
expect(question.min).to eq(0)
end
it "has the correct prefix" do
expect(question.prefix).to eq("£")
end
end

1
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -21,6 +21,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
mortgage_amount_discounted_ownership
about_deposit_discounted_ownership
discounted_ownership_deposit_value_check
leasehold_charges_discounted_ownership
],
)
end

7
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -13,11 +13,14 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
it "has correct pages" do
expect(outright_sale.pages.map(&:id)).to eq(
%w[purchase_price
%w[
purchase_price
mortgage_used_outright_sale
mortgage_amount_outright_sale
about_deposit_outright_sale
outright_sale_deposit_value_check],
outright_sale_deposit_value_check
leasehold_charges_outright_sale
],
)
end

1
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -29,6 +29,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
about_deposit_shared_ownership
shared_ownership_deposit_value_check
monthly_rent
leasehold_charges_shared_ownership
],
)
end

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(122)
expect(form.pages.count).to eq(125)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(122)
expect(form.pages.count).to eq(125)
expect(form.name).to eq("2021_2022_sales")
end
end

Loading…
Cancel
Save