Browse Source

Add. local authority to database

CLDC-858-update-sales-property-information
Mo Seedat 2 years ago
parent
commit
c31e8765a8
  1. 16
      app/models/form/sales/pages/purchase_price.rb
  2. 40
      app/models/form/sales/questions/local_authority.rb
  3. 12
      app/models/form/sales/questions/purchase_price.rb
  4. 1
      app/models/form/sales/subsections/property_information.rb
  5. 2
      app/models/local_authority.rb
  6. 12
      app/models/sales_log.rb
  7. 1
      config/local_authority_data/la-2022.csv
  8. 2658
      config/sales_range_data/2022.csv
  9. 3
      db/migrate/20221016203810_create_la_sales_ranges.rb
  10. 6
      db/migrate/20221016220117_add_purchase_price_to_sales_log.rb
  11. 11
      db/migrate/20221016221451_create_local_authorities.rb
  12. 15
      db/schema.rb

16
app/models/form/sales/pages/purchase_price.rb

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

40
app/models/form/sales/questions/local_authority.rb

@ -0,0 +1,40 @@
class Form::Sales::Questions::LocalAuthority < ::Form::Question
def initialize(id, hsh, page)
super
@id = "la"
@check_answer_label = "Local authority"
@header = "Which area is this property in?"
@hint_text = "Where this property is located."
@type = "select"
@width = 10
@page = page
end
#LAD11NM value mapping
def answer_options
answer_opts = { "" => "Select an option" }
return answer_opts unless ActiveRecord::Base.connected?
LocalAuthority.select(:id, :name).each_with_object(answer_opts) do |local_authority, hsh|
hsh[local_authority.id] = local_authority.name
hsh
end
end
def displayed_answer_options(_log)
answer_options
end
def label_from_value(value)
return unless value
answer_options[value]
end
def hidden_in_check_answers?(_log, current_user)
!current_user.support?
end
def derived?
true
end
end

12
app/models/form/sales/questions/purchase_price.rb

@ -0,0 +1,12 @@
class Form::Sales::Questions::PurchasePrice < ::Form::Question
def initialize(id, hsh, page)
super
@id = "purchase_price"
@check_answer_label = "Purchase price"
@header = "What is the purchase price?"
@hint_text = "This is how much the buyer paid for the actual sale price."
@type = "text"
@width = 10
@page = page
end
end

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

@ -12,6 +12,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
Form::Sales::Pages::PropertyNumberOfBedrooms.new(nil, nil, self),
Form::Sales::Pages::PropertyBuildingType.new(nil, nil, self),
Form::Sales::Pages::PropertyUnitType.new(nil, nil, self),
Form::Sales::Pages::PurchasePrice.new(nil, nil, self),
]
end
end

2
app/models/local_authority.rb

@ -0,0 +1,2 @@
class LocalAuthority < ApplicationRecord
end

12
app/models/sales_log.rb

@ -61,4 +61,16 @@ class SalesLog < Log
def bedsit?
proptype == 2
end
# num beds greater than found in db?
# LA not in DB then?
def soft_min_for_purchase_price
soft_min = LaSalesRange.find_by(la:, beds:).soft_min
"#{soft_min}"
end
def soft_max_for_purchase_price
soft_max = LaSalesRange.find_by(la:, beds:).soft_max
"#{soft_max}"
end
end

1
config/local_authority_data/la-2022.csv

@ -0,0 +1 @@
ons_code,name
1 ons_code name

2658
config/sales_range_data/2022.csv

File diff suppressed because it is too large Load Diff

3
db/migrate/20221016203810_create_la_sales_ranges.rb

@ -6,9 +6,8 @@ class CreateLaSalesRanges < ActiveRecord::Migration[7.0]
t.integer :beds
t.integer :soft_min, null: false
t.integer :soft_max, null: false
t.integer :start_year, null: false
t.index %i[start_year beds la], unique: true
t.index %i[beds la], unique: true
t.timestamps
end
end

6
db/migrate/20221016220117_add_purchase_price_to_sales_log.rb

@ -0,0 +1,6 @@
class AddPurchasePriceToSalesLog < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :la, :string
add_column :sales_logs, :purchase_price, :integer
end
end

11
db/migrate/20221016221451_create_local_authorities.rb

@ -0,0 +1,11 @@
class CreateLocalAuthorities < ActiveRecord::Migration[7.0]
def change
create_table :local_authorities do |t|
t.string :ons_code, null: false
t.string :name, null: false
t.index %i[ons_code name], unique: true # Only one entry per LA
t.timestamps
end
end
end

15
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_10_16_203810) do
ActiveRecord::Schema[7.0].define(version: 2022_10_16_221451) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -48,10 +48,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_16_203810) do
t.integer "beds"
t.integer "soft_min", null: false
t.integer "soft_max", null: false
t.integer "start_year", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["start_year", "beds", "la"], name: "index_la_sales_ranges_on_start_year_and_beds_and_la", unique: true
t.index ["beds", "la"], name: "index_la_sales_ranges_on_beds_and_la", unique: true
end
create_table "legacy_users", force: :cascade do |t|
@ -257,6 +256,14 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_16_203810) do
t.index ["scheme_id"], name: "index_lettings_logs_on_scheme_id"
end
create_table "local_authorities", force: :cascade do |t|
t.string "ons_code", null: false
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["ons_code", "name"], name: "index_local_authorities_on_ons_code_and_name", unique: true
end
create_table "locations", force: :cascade do |t|
t.string "location_code"
t.string "postcode"
@ -370,6 +377,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_16_203810) do
t.integer "hholdcount"
t.integer "age3"
t.integer "age3_known"
t.string "la"
t.integer "purchase_price"
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"

Loading…
Cancel
Save