Browse Source

feat: add hard income validations to uprn question

pull/1553/head
natdeanlewissoftwire 3 years ago
parent
commit
98faef75b7
  1. 2
      app/models/form/lettings/questions/uprn.rb
  2. 2
      app/models/form/sales/questions/uprn.rb
  3. 4
      app/models/lettings_log.rb
  4. 4
      app/models/sales_log.rb
  5. 2
      app/models/validations/financial_validations.rb
  6. 6
      app/models/validations/sales/financial_validations.rb
  7. 3
      config/locales/en.yml
  8. 15
      db/schema.rb
  9. 2
      spec/models/form/lettings/questions/uprn_spec.rb
  10. 2
      spec/models/form/sales/questions/uprn_spec.rb

2
app/models/form/lettings/questions/uprn.rb

@ -3,7 +3,7 @@ class Form::Lettings::Questions::Uprn < ::Form::Question
super
@id = "uprn"
@check_answer_label = "UPRN"
@header = "What is the property's UPRN"
@header = "What is the property's UPRN?"
@type = "text"
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355."
@width = 10

2
app/models/form/sales/questions/uprn.rb

@ -3,7 +3,7 @@ class Form::Sales::Questions::Uprn < ::Form::Question
super
@id = "uprn"
@check_answer_label = "UPRN"
@header = "What is the property's UPRN"
@header = "What is the property's UPRN?"
@type = "text"
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355."
@width = 10

4
app/models/lettings_log.rb

@ -33,7 +33,7 @@ class LettingsLog < Log
before_validation :reset_location_fields!, unless: :postcode_known?
before_validation :reset_previous_location_fields!, unless: :previous_postcode_known?
before_validation :set_derived_fields!
after_validation :process_uprn_change!, if: :should_process_uprn_change?
before_validation :process_uprn_change!, if: :should_process_uprn_change?
belongs_to :scheme, optional: true
belongs_to :location, optional: true
@ -671,6 +671,6 @@ private
end
def should_process_uprn_change?
uprn_changed? && startdate && startdate.year >= 2023
uprn && stardate && (uprn_changed? || stardate_changed?) && stardate.year >= 2023
end
end

4
app/models/sales_log.rb

@ -32,7 +32,7 @@ class SalesLog < Log
before_validation :reset_location_fields!, unless: :postcode_known?
before_validation :reset_previous_location_fields!, unless: :previous_postcode_known?
before_validation :set_derived_fields!
after_validation :process_uprn_change!, if: :should_process_uprn_change?
before_validation :process_uprn_change!, if: :should_process_uprn_change?
scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :filter_by_purchaser_code, ->(purchid) { where("purchid ILIKE ?", "%#{purchid}%") }
@ -324,7 +324,7 @@ class SalesLog < Log
end
def should_process_uprn_change?
uprn_changed? && saledate && saledate.year >= 2023
uprn && saledate && (uprn_changed? || saledate_changed?) && saledate.year >= 2023
end
def value_with_discount

2
app/models/validations/financial_validations.rb

@ -214,6 +214,7 @@ private
if record.weekly_value(record["brent"]) < rent_range.hard_min
record.errors.add :brent, I18n.t("validations.financial.brent.below_hard_min")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.below_hard_min")
record.errors.add :uprn, I18n.t("validations.financial.brent.uprn.below_hard_min")
record.errors.add :la, I18n.t("validations.financial.brent.la.below_hard_min")
record.errors.add :postcode_known, I18n.t("validations.financial.brent.postcode_known.below_hard_min")
record.errors.add :scheme_id, I18n.t("validations.financial.brent.scheme_id.below_hard_min")
@ -226,6 +227,7 @@ private
if record.weekly_value(record["brent"]) > rent_range.hard_max
record.errors.add :brent, :over_hard_max, message: I18n.t("validations.financial.brent.above_hard_max")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max")
record.errors.add :uprn, I18n.t("validations.financial.brent.uprn.above_hard_max")
record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max")
record.errors.add :postcode_known, I18n.t("validations.financial.brent.postcode_known.above_hard_max")
record.errors.add :scheme_id, I18n.t("validations.financial.brent.scheme_id.above_hard_max")

6
app/models/validations/sales/financial_validations.rb

@ -5,7 +5,7 @@ module Validations::Sales::FinancialValidations
def validate_income1(record)
return unless record.income1 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income1 ownershipsch la postcode_full]
relevant_fields = %i[income1 ownershipsch uprn la postcode_full]
if record.london_property? && record.income1 > 90_000
relevant_fields.each { |field| record.errors.add field, I18n.t("validations.financial.income.over_hard_max_for_london") }
elsif record.property_not_in_london? && record.income1 > 80_000
@ -16,7 +16,7 @@ module Validations::Sales::FinancialValidations
def validate_income2(record)
return unless record.income2 && record.la && record.shared_ownership_scheme?
relevant_fields = %i[income2 ownershipsch la postcode_full]
relevant_fields = %i[income2 ownershipsch uprn la postcode_full]
if record.london_property? && record.income2 > 90_000
relevant_fields.each { |field| record.errors.add field, I18n.t("validations.financial.income.over_hard_max_for_london") }
elsif record.property_not_in_london? && record.income2 > 80_000
@ -28,7 +28,7 @@ module Validations::Sales::FinancialValidations
return unless record.income1 && record.income2 && record.la && record.shared_ownership_scheme?
combined_income = record.income1 + record.income2
relevant_fields = %i[income1 income2 ownershipsch la postcode_full]
relevant_fields = %i[income1 income2 ownershipsch uprn la postcode_full]
if record.london_property? && combined_income > 90_000
relevant_fields.each { |field| record.errors.add field, I18n.t("validations.financial.income.combined_over_hard_max_for_london") }
elsif record.property_not_in_london? && combined_income > 80_000

3
config/locales/en.yml

@ -296,6 +296,9 @@ en:
postcode_known:
below_hard_min: "Rent is below the absolute minimum expected for a property of this type. Please check the rent, rent period, local authority and number of bedrooms"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and number of bedrooms"
uprn:
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this UPRN"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this UPRN"
la:
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this local authority"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this local authority"

15
db/schema.rb

@ -519,6 +519,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_12_143245) do
t.integer "prevten"
t.integer "mortgageused"
t.integer "wchair"
t.integer "income2_value_check"
t.integer "armedforcesspouse"
t.datetime "hodate", precision: nil
t.integer "hoday"
@ -543,14 +544,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_12_143245) do
t.integer "retirement_value_check"
t.integer "hodate_check"
t.integer "extrabor_value_check"
t.integer "grant_value_check"
t.integer "staircase_bought_value_check"
t.integer "deposit_and_mortgage_value_check"
t.integer "shared_ownership_deposit_value_check"
t.integer "grant_value_check"
t.integer "value_value_check"
t.integer "old_persons_shared_ownership_value_check"
t.integer "income2_value_check"
t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check"
t.integer "value_value_check"
t.integer "details_known_5"
t.integer "details_known_6"
t.integer "saledate_check"
@ -560,10 +560,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_12_143245) do
t.integer "ethnicbuy2"
t.integer "proplen_asked"
t.string "old_id"
t.integer "pregblank"
t.integer "buy2living"
t.integer "prevtenbuy2"
t.integer "nationalbuy2"
t.integer "pregblank"
t.string "uprn"
t.integer "uprn_known"
t.integer "uprn_confirmed"
@ -571,10 +570,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_12_143245) do
t.string "address_line2"
t.string "town_or_city"
t.string "county"
t.integer "nationalbuy2"
t.integer "discounted_sale_value_check"
t.integer "student_not_child_value_check"
t.integer "buyer_livein_value_check"
t.integer "combined_income_value_check"
t.integer "percentage_discount_value_check"
t.integer "buyer_livein_value_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true

2
spec/models/form/lettings/questions/uprn_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
end
it "has the correct header" do
expect(question.header).to eq("What is the property's UPRN")
expect(question.header).to eq("What is the property's UPRN?")
end
it "has the correct check_answer_label" do

2
spec/models/form/sales/questions/uprn_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
end
it "has the correct header" do
expect(question.header).to eq("What is the property's UPRN")
expect(question.header).to eq("What is the property's UPRN?")
end
it "has the correct check_answer_label" do

Loading…
Cancel
Save