Browse Source

Cldc 1543 mortgage used (#1139)

* Add sale_information section

* Switch the order of sales log sections

* Add mortgageused column

* Add mortgageused page and question

* Add mortgageused page to subsections

* derive deposit

* tests
chloe-1
kosiakkatrina 2 years ago committed by GitHub
parent
commit
f0ff0fec2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/derived_variables/sales_log_variables.rb
  2. 14
      app/models/form/sales/pages/mortgageused.rb
  3. 17
      app/models/form/sales/questions/mortgageused.rb
  4. 1
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  5. 1
      app/models/form/sales/subsections/outright_sale.rb
  6. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  7. 8
      app/models/sales_log.rb
  8. 7
      db/migrate/20230104083951_add_mortgageused.rb
  9. 1
      db/schema.rb
  10. 1
      spec/factories/sales_log.rb
  11. 29
      spec/models/form/sales/pages/mortgageused_spec.rb
  12. 48
      spec/models/form/sales/questions/mortgageused_spec.rb
  13. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  14. 1
      spec/models/form/sales/subsections/outright_sale_spec.rb
  15. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  16. 4
      spec/models/form_handler_spec.rb
  17. 25
      spec/models/sales_log_spec.rb

1
app/models/derived_variables/sales_log_variables.rb

@ -6,5 +6,6 @@ module DerivedVariables::SalesLogVariables
self.exmonth = exdate.month
self.exyear = exdate.year
end
self.deposit = value if outright_sale? && mortgage_not_used?
end
end

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

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

17
app/models/form/sales/questions/mortgageused.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::Mortgageused < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mortgageused"
@check_answer_label = "Mortgage used"
@header = "Was a mortgage used for the purchase of this property?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

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

@ -12,6 +12,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
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),

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

@ -10,6 +10,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::PurchasePrice.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_outright_sale", nil, self),
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),

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

@ -18,6 +18,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::BuyerPrevious.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self),

8
app/models/sales_log.rb

@ -143,4 +143,12 @@ class SalesLog < Log
self[la_inferred_key] = inferred_la.present?
self[la_key] = inferred_la if inferred_la.present?
end
def outright_sale?
ownershipsch == 3
end
def mortgage_not_used?
mortgageused == 2
end
end

7
db/migrate/20230104083951_add_mortgageused.rb

@ -0,0 +1,7 @@
class AddMortgageused < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :mortgageused, :integer
end
end
end

1
db/schema.rb

@ -458,6 +458,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_04_164318) do
t.integer "savings_value_check"
t.integer "deposit_value_check"
t.integer "hb"
t.integer "mortgageused"
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"

1
spec/factories/sales_log.rb

@ -87,6 +87,7 @@ FactoryBot.define do
relat5 { "P" }
relat6 { "P" }
hb { 4 }
mortgageused { 1 }
end
end
end

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

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Mortgageused, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "mortgage_used" }
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[mortgageused])
end
it "has the correct id" do
expect(page.id).to eq("mortgage_used")
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
end

48
spec/models/form/sales/questions/mortgageused_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Mortgageused, 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("mortgageused")
end
it "has the correct header" do
expect(question.header).to eq("Was a mortgage used for the purchase of this property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Mortgage used")
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({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
end

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

@ -17,6 +17,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
living_before_purchase_discounted_ownership
about_price_rtb
about_price_not_rtb
mortgage_used_discounted_ownership
mortgage_amount_discounted_ownership
about_deposit_discounted_ownership
discounted_ownership_deposit_value_check

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

@ -14,6 +14,7 @@ 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
mortgage_used_outright_sale
mortgage_amount_outright_sale
about_deposit_outright_sale
outright_sale_deposit_value_check],

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

@ -23,6 +23,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
buyer_previous
previous_bedrooms
about_price_shared_ownership
mortgage_used_shared_ownership
mortgage_amount_shared_ownership
about_deposit_with_discount
about_deposit_shared_ownership

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(113)
expect(form.pages.count).to eq(116)
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(113)
expect(form.pages.count).to eq(116)
expect(form.name).to eq("2021_2022_sales")
end
end

25
spec/models/sales_log_spec.rb

@ -92,18 +92,33 @@ RSpec.describe SalesLog, type: :model do
end
describe "derived variables" do
let!(:sales_log) do
described_class.create({
exdate: Time.gm(2022, 5, 4),
})
end
let(:sales_log) { FactoryBot.create(:sales_log, :completed) }
it "correctly derives and saves exday, exmonth and exyear" do
sales_log.update!(exdate: Time.gm(2022, 5, 4))
record_from_db = ActiveRecord::Base.connection.execute("select exday, exmonth, exyear from sales_logs where id=#{sales_log.id}").to_a[0]
expect(record_from_db["exday"]).to eq(4)
expect(record_from_db["exmonth"]).to eq(5)
expect(record_from_db["exyear"]).to eq(2022)
end
it "correctly derives and saves deposit for outright sales when no mortgage is used" do
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1)
record_from_db = ActiveRecord::Base.connection.execute("select deposit from sales_logs where id=#{sales_log.id}").to_a[0]
expect(record_from_db["deposit"]).to eq(123_400)
end
it "does not derive deposit if the sale isn't outright" do
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 2, ownershipsch: 2)
record_from_db = ActiveRecord::Base.connection.execute("select deposit from sales_logs where id=#{sales_log.id}").to_a[0]
expect(record_from_db["deposit"]).to eq(nil)
end
it "does not derive deposit if the mortgage is used" do
sales_log.update!(value: 123_400, deposit: nil, mortgageused: 1, ownershipsch: 3, type: 10, companybuy: 1, jointpur: 1, jointmore: 1)
record_from_db = ActiveRecord::Base.connection.execute("select deposit from sales_logs where id=#{sales_log.id}").to_a[0]
expect(record_from_db["deposit"]).to eq(nil)
end
end
context "when saving previous address" do

Loading…
Cancel
Save