diff --git a/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb b/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb index 35fefd7fd..218f17c5e 100644 --- a/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb +++ b/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 diff --git a/app/models/log.rb b/app/models/log.rb index 0d0df6451..a8c01f930 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -28,10 +28,19 @@ class Log < ApplicationRecord def collection_start_year return @start_year if @start_year - return unless startdate - window_end_date = Time.zone.local(startdate.year, 4, 1) - @start_year = startdate < window_end_date ? startdate.year - 1 : startdate.year + if lettings? + return unless startdate + + 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? diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 11049e8ff..e03f31b83 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/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 diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 3bc9dab1f..8c668b5e1 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index f61fb6599..8fecd0590 100644 --- a/db/schema.rb +++ b/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"