Browse Source

CLDC-4333: update purchase price soft vals to take stairbought into account

pull/3270/head
Nat Dean-Lewis 1 week ago
parent
commit
b09c78679e
  1. 15
      app/models/validations/sales/soft_validations.rb
  2. 57
      spec/models/validations/sales/soft_validations_spec.rb

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

@ -96,8 +96,9 @@ module Validations::Sales::SoftValidations
def purchase_price_out_of_soft_range?
return unless value && beds && la && sale_range
return if is_staircase? && !stairbought&.positive?
!value.between?(sale_range.soft_min, sale_range.soft_max)
!full_purchase_price.between?(sale_range.soft_min, sale_range.soft_max)
end
def staircase_owned_out_of_soft_range?
@ -136,11 +137,11 @@ module Validations::Sales::SoftValidations
end
def purchase_price_higher_or_lower_text
value < sale_range.soft_min ? "lower" : "higher"
full_purchase_price < sale_range.soft_min ? "lower" : "higher"
end
def purchase_price_soft_min_or_soft_max
value < sale_range.soft_min ? sale_range.soft_min : sale_range.soft_max
full_purchase_price < sale_range.soft_min ? sale_range.soft_min : sale_range.soft_max
end
def grant_outside_common_range?
@ -203,6 +204,14 @@ module Validations::Sales::SoftValidations
private
def full_purchase_price
if is_staircase? && stairbought&.positive?
value * 100 / stairbought
else
value
end
end
def sale_range
LaSaleRange.find_by(
start_year: collection_start_year,

57
spec/models/validations/sales/soft_validations_spec.rb

@ -808,6 +808,63 @@ RSpec.describe Validations::Sales::SoftValidations do
expect(record).not_to be_purchase_price_out_of_soft_range
end
context "when staircasing" do
it "is not out of range when stairbought is 10% and value is 20,000 (full price 200,000 is in soft range)" do
record.staircase = 1
record.stairbought = 10
record.value = 20_000
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).not_to be_purchase_price_out_of_soft_range
end
it "is out of range when stairbought is 10% and value is 17,000 (full price 170,000 is below soft min of 177,000)" do
record.staircase = 1
record.stairbought = 10
record.value = 17_000
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).to be_purchase_price_out_of_soft_range
end
it "is out of range when stairbought is 10% and value is 40,000 (full price 400,000 is above soft max of 384,000)" do
record.staircase = 1
record.stairbought = 10
record.value = 40_000
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).to be_purchase_price_out_of_soft_range
end
it "does not trigger when stairbought is not set" do
record.staircase = 1
record.stairbought = nil
record.value = 20_000
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).not_to be_purchase_price_out_of_soft_range
end
it "does not trigger when stairbought is 0" do
record.staircase = 1
record.stairbought = 0
record.value = 20_000
record.beds = 2
record.la = "E07000223"
record.saledate = Time.zone.local(2023, 1, 1)
expect(record).not_to be_purchase_price_out_of_soft_range
end
end
end
describe "#grant_outside_common_range?" do

Loading…
Cancel
Save