Browse Source

[CLDC-1746] Add HandoverDate question (#1161)

pull/1168/head
Jack 2 years ago committed by GitHub
parent
commit
2f9e3d7d71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/derived_variables/sales_log_variables.rb
  2. 18
      app/models/form/sales/pages/handover_date.rb
  3. 11
      app/models/form/sales/questions/handover_date.rb
  4. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  5. 8
      db/migrate/20230106145107_add_handover_date_to_sales_log.rb
  6. 6
      db/schema.rb
  7. 35
      spec/models/form/sales/pages/handover_date_spec.rb
  8. 33
      spec/models/form/sales/questions/handover_date_spec.rb
  9. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  10. 4
      spec/models/form_handler_spec.rb

5
app/models/derived_variables/sales_log_variables.rb

@ -6,6 +6,11 @@ module DerivedVariables::SalesLogVariables
self.exmonth = exdate.month self.exmonth = exdate.month
self.exyear = exdate.year self.exyear = exdate.year
end end
if hodate.present?
self.hoday = hodate.day
self.homonth = hodate.month
self.hoyear = hodate.year
end
self.deposit = value if outright_sale? && mortgage_not_used? self.deposit = value if outright_sale? && mortgage_not_used?
if mscharge_known.present? && mscharge_known.zero? if mscharge_known.present? && mscharge_known.zero?
self.mscharge = 0 self.mscharge = 0

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::HandoverDate < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "handover_date"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"ownershipsch" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::HandoverDate.new(nil, nil, self),
]
end
end

11
app/models/form/sales/questions/handover_date.rb

@ -0,0 +1,11 @@
class Form::Sales::Questions::HandoverDate < ::Form::Question
def initialize(id, hsh, page)
super
@id = "hodate"
@check_answer_label = "Practical completion or handover date"
@header = "What is the practical completion or handover date?"
@type = "date"
@page = page
@hint_text = "This is the date on which the building contractor hands over responsibility for the completed property to the private registered provider (PRP)"
end
end

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

@ -14,6 +14,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutStaircase.new(nil, nil, self), Form::Sales::Pages::AboutStaircase.new(nil, nil, self),
Form::Sales::Pages::Resale.new(nil, nil, self), Form::Sales::Pages::Resale.new(nil, nil, self),
Form::Sales::Pages::ExchangeDate.new(nil, nil, self), Form::Sales::Pages::ExchangeDate.new(nil, nil, self),
Form::Sales::Pages::HandoverDate.new(nil, nil, self),
Form::Sales::Pages::LaNominations.new(nil, nil, self), Form::Sales::Pages::LaNominations.new(nil, nil, self),
Form::Sales::Pages::BuyerPrevious.new(nil, nil, self), Form::Sales::Pages::BuyerPrevious.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),

8
db/migrate/20230106145107_add_handover_date_to_sales_log.rb

@ -0,0 +1,8 @@
class AddHandoverDateToSalesLog < ActiveRecord::Migration[7.0]
change_table :sales_logs, bulk: true do |t|
t.column :hodate, :datetime
t.column :hoday, :integer
t.column :homonth, :integer
t.column :hoyear, :integer
end
end

6
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do ActiveRecord::Schema[7.0].define(version: 2023_01_06_145107) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -466,6 +466,10 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do
t.string "sex4" t.string "sex4"
t.string "sex5" t.string "sex5"
t.string "sex6" t.string "sex6"
t.datetime "hodate", precision: nil
t.integer "hoday"
t.integer "homonth"
t.integer "hoyear"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" 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 ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::HandoverDate, 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[hodate])
end
it "has the correct id" do
expect(page.id).to eq("handover_date")
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 the correct depends_on" do
expect(page.depends_on).to eq([{
"ownershipsch" => 1,
}])
end
end

33
spec/models/form/sales/questions/handover_date_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::HandoverDate, 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("hodate")
end
it "has the correct header" do
expect(question.header).to eq("What is the practical completion or handover date?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Practical completion or handover date")
end
it "has the correct type" do
expect(question.type).to eq("date")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
end

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

@ -19,6 +19,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
about_staircasing about_staircasing
resale resale
exchange_contracts exchange_contracts
handover_date
la_nominations la_nominations
buyer_previous buyer_previous
previous_bedrooms previous_bedrooms

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 it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(131) expect(form.pages.count).to eq(132)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(131) expect(form.pages.count).to eq(132)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

Loading…
Cancel
Save