Browse Source

feat: fix hodate validation and use purchase price ranges

pull/1225/head
natdeanlewissoftwire 2 years ago
parent
commit
be38ac3e39
  1. 6
      app/models/form/sales/questions/about_price_shared_ownership_value_check.rb
  2. 13
      app/models/log.rb
  3. 4
      app/models/validations/sales/sale_information_validations.rb
  4. 5
      app/models/validations/sales/soft_validations.rb
  5. 1
      db/schema.rb

6
app/models/form/sales/questions/about_price_shared_ownership_value_check.rb

@ -3,7 +3,7 @@ class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Ques
super
@id = "value_value_check"
@check_answer_label = "Deposit confirmation"
@header = "Are you sure? You said purchase price was PRICE, which seems high"
@header = "Are you sure? This purchase price is outside the expected range for this local authority and number of bedrooms"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
@ -20,8 +20,4 @@ class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Ques
],
}
end
def value_is_high?(value)
true
end
end

13
app/models/log.rb

@ -28,10 +28,19 @@ class Log < ApplicationRecord
def collection_start_year
return @start_year if @start_year
if lettings?
return unless startdate
window_end_date = Time.zone.local(startdate.year, 4, 1)
@start_year = startdate < window_end_date ? startdate.year - 1 : startdate.year
log_start_date = startdate
else
return unless saledate
log_start_date = saledate
end
window_end_date = Time.zone.local(log_start_date.year, 4, 1)
@start_year = log_start_date < window_end_date ? log_start_date.year - 1 : log_start_date.year
end
def lettings?

4
app/models/validations/sales/sale_information_validations.rb

@ -8,9 +8,9 @@ module Validations::Sales::SaleInformationValidations
end
def validate_pratical_completion_date_before_saledate(record)
return if record.saledate.blank? || record.hodate.blank?
return if record.exdate.blank? || record.hodate.blank?
unless record.saledate > record.hodate
unless record.exdate > record.hodate
record.errors.add :hodate, "Practical completion or handover date must be before exchange date"
end
end

5
app/models/validations/sales/soft_validations.rb

@ -44,8 +44,9 @@ module Validations::Sales::SoftValidations
end
def purchase_price_out_of_expected_range?
return unless value
return unless value && beds && la
true
purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds)
purchase_price_range.present? && !value.between?(purchase_price_range.soft_min, purchase_price_range.soft_max)
end
end

1
db/schema.rb

@ -510,7 +510,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_24_111328) do
t.string "postcode_full"
t.boolean "is_la_inferred"
t.integer "hodate_check"
t.integer "extrabor_value_check"
t.integer "value_value_check"
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"

Loading…
Cancel
Save