Browse Source

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
pull/1130/head
kosiakkatrina 4 years ago committed by Kat
parent
commit
df515d45ca
  1. 18
      app/models/form/sales/pages/about_price.rb
  2. 19
      app/models/form/sales/pages/about_price_not_rtb.rb
  3. 19
      app/models/form/sales/pages/about_price_rtb.rb
  4. 19
      app/models/form/sales/pages/about_price_social_housing.rb
  5. 17
      app/models/form/sales/questions/discount.rb
  6. 15
      app/models/form/sales/questions/equity.rb
  7. 14
      app/models/form/sales/questions/grant.rb
  8. 14
      app/models/form/sales/questions/value.rb
  9. 2
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  10. 2
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  11. 4
      app/models/sales_log.rb
  12. 10
      db/migrate/20221222133600_add_price_fields.rb
  13. 4
      db/schema.rb
  14. 2
      spec/factories/sales_log.rb
  15. 35
      spec/models/form/sales/pages/about_price_not_rtb_spec.rb
  16. 35
      spec/models/form/sales/pages/about_price_rtb_spec.rb
  17. 35
      spec/models/form/sales/pages/about_price_social_housing_spec.rb
  18. 35
      spec/models/form/sales/pages/about_price_spec.rb
  19. 55
      spec/models/form/sales/questions/discount_spec.rb
  20. 53
      spec/models/form/sales/questions/equity_spec.rb
  21. 49
      spec/models/form/sales/questions/grant_spec.rb
  22. 49
      spec/models/form/sales/questions/value_spec.rb
  23. 4
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  24. 2
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  25. 4
      spec/models/form_handler_spec.rb

18
app/models/form/sales/pages/about_price.rb

@ -0,0 +1,18 @@
class Form::Sales::Pages::AboutPrice < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price"
@header = "About the price of the property"
@description = ""
@subsection = subsection
@depends_on = [{
"soctenant" => 2,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
]
end
end

19
app/models/form/sales/pages/about_price_not_rtb.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::AboutPriceNotRtb < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_not_rtb"
@header = "About the price of the property"
@description = ""
@subsection = subsection
@depends_on = [{
"right_to_buy?" => false,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Grant.new(nil, nil, self),
]
end
end

19
app/models/form/sales/pages/about_price_rtb.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::AboutPriceRtb < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_rtb"
@header = "About the price of the property"
@description = ""
@subsection = subsection
@depends_on = [{
"right_to_buy?" => true,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Discount.new(nil, nil, self),
]
end
end

19
app/models/form/sales/pages/about_price_social_housing.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::AboutPriceSocialHousing < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_social_housing"
@header = "About the price of the property"
@description = ""
@subsection = subsection
@depends_on = [{
"soctenant" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Equity.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,17 @@
class Form::Sales::Questions::Discount < ::Form::Question
def initialize(id, hsh, page)
super
@id = "discount"
@check_answer_label = "Percentage discount"
@header = "What was the percentage discount?"
@type = "numeric"
@page = page
@min = 0
@max = 100
@width = 5
@suffix = "%"
@hint_text = "For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB)
If discount capped, enter capped %
If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given."
end
end

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

@ -0,0 +1,15 @@
class Form::Sales::Questions::Equity < ::Form::Question
def initialize(id, hsh, page)
super
@id = "equity"
@check_answer_label = "Initial percentage equity stake"
@header = "What was the initial percentage equity stake purchased?"
@type = "numeric"
@page = page
@min = 0
@max = 100
@width = 5
@suffix = "%"
@hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)"
end
end

14
app/models/form/sales/questions/grant.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::Grant < ::Form::Question
def initialize(id, hsh, page)
super
@id = "grant"
@check_answer_label = "Amount of any loan, grant or subsidy"
@header = "What was the amount of any loan, grant, discount or subsidy given?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)"
end
end

14
app/models/form/sales/questions/value.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::Value < ::Form::Question
def initialize(id, hsh, page)
super
@id = "value"
@check_answer_label = "Full purchase price"
@header = "What was the full purchase price?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)"
end
end

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

@ -10,6 +10,8 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::AboutDeposit.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceRtb.new("about_deposit_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new("about_deposit_discounted_ownership", nil, self),
]
end

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

@ -15,6 +15,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::LaNominations.new(nil, nil, self),
Form::Sales::Pages::BuyerPrevious.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),
Form::Sales::Pages::AboutPrice.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSocialHousing.new(nil, nil, self),
Form::Sales::Pages::AboutDeposit.new("about_deposit_shared_ownership", nil, self),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
Form::Sales::Pages::ExchangeDate.new(nil, nil, self),

4
app/models/sales_log.rb

@ -111,4 +111,8 @@ class SalesLog < Log
def income2_used_for_mortgage?
inc2mort == 1
end
def right_to_buy?
[9, 14, 27].include?(type)
end
end

10
db/migrate/20221222133600_add_price_fields.rb

@ -0,0 +1,10 @@
class AddPriceFields < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :value, :decimal, precision: 10, scale: 2
t.column :equity, :decimal, precision: 10, scale: 2
t.column :discount, :decimal, precision: 10, scale: 2
t.column :grant, :decimal, precision: 10, scale: 2
end
end
end

4
db/schema.rb

@ -430,6 +430,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_22_133600) do
t.decimal "cashdis", precision: 10, scale: 2
t.integer "lanomagr"
t.integer "soctenant"
t.decimal "value", precision: 10, scale: 2
t.decimal "equity", precision: 10, scale: 2
t.decimal "discount", precision: 10, scale: 2
t.decimal "grant", 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

@ -70,6 +70,8 @@ FactoryBot.define do
disabled { 2 }
deposit { 10_000 }
cashdis { 1_000 }
value { 110_000 }
grant { 1_000 }
end
end
end

35
spec/models/form/sales/pages/about_price_not_rtb_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPriceNotRtb, 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[value grant])
end
it "has the correct id" do
expect(page.id).to eq("about_price_not_rtb")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"right_to_buy?" => false,
}])
end
end

35
spec/models/form/sales/pages/about_price_rtb_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPriceRtb, 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[value discount])
end
it "has the correct id" do
expect(page.id).to eq("about_price_rtb")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"right_to_buy?" => true,
}])
end
end

35
spec/models/form/sales/pages/about_price_social_housing_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPriceSocialHousing, 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[value equity])
end
it "has the correct id" do
expect(page.id).to eq("about_price_social_housing")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"soctenant" => 1,
}])
end
end

35
spec/models/form/sales/pages/about_price_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPrice, 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[value])
end
it "has the correct id" do
expect(page.id).to eq("about_price")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"soctenant" => 2,
}])
end
end

55
spec/models/form/sales/questions/discount_spec.rb

@ -0,0 +1,55 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Discount, 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("discount")
end
it "has the correct header" do
expect(question.header).to eq("What was the percentage discount?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Percentage discount")
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 eq("For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB)
If discount capped, enter capped %
If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given.")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct suffix" do
expect(question.suffix).to eq("%")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(100)
end
end

53
spec/models/form/sales/questions/equity_spec.rb

@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Equity, 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("equity")
end
it "has the correct header" do
expect(question.header).to eq("What was the initial percentage equity stake purchased?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Initial percentage equity stake")
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 eq("Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct suffix" do
expect(question.suffix).to eq("%")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(100)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Grant, 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("grant")
end
it "has the correct header" do
expect(question.header).to eq("What was the amount of any loan, grant, discount or subsidy given?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Amount of any loan, grant or subsidy")
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 eq("For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Value, 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("value")
end
it "has the correct header" do
expect(question.header).to eq("What was the full purchase price?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Full purchase price")
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 eq("Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -13,7 +13,9 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[about_deposit_discounted_ownership],
%w[about_deposit_discounted_ownership
about_price_rtb
about_price_not_rtb],
)
end

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

@ -20,6 +20,8 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
la_nominations
buyer_previous
previous_bedrooms
about_price
about_price_social_housing
about_deposit_shared_ownership
monthly_rent
exchange_contracts

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

Loading…
Cancel
Save