Browse Source

feat: update validations when beds > 4

pull/959/head
natdeanlewissoftwire 3 years ago
parent
commit
58d1a742fe
  1. 3
      app/models/lettings_log.rb
  2. 27
      app/models/validations/financial_validations.rb
  3. 7
      app/models/validations/soft_validations.rb

3
app/models/lettings_log.rb

@ -436,10 +436,11 @@ class LettingsLog < Log
end
def validation_beds
max_beds_in_rent_ranges = 4
if needstype == 2
0
else
beds.nil? ? nil : [beds, 4].min
beds.nil? ? nil : [beds, max_beds_in_rent_ranges].min
end
end

27
app/models/validations/financial_validations.rb

@ -182,18 +182,19 @@ private
collection_year = record.collection_start_year
beds = if record.needstype == 2
0
else
record.beds.nil? ? nil : [record.beds, 4].min
end
la = if record.needstype == 2
defined?(record.location.location_code) ? record.location.location_code : nil
else
record.la
end
rent_range = LaRentRange.find_by(start_year: collection_year, la:, beds:, lettype: record.lettype)
max_beds_in_rent_ranges = 4
validation_beds = if record.needstype == 2
0
else
record.beds.nil? ? nil : [record.beds, max_beds_in_rent_ranges].min
end
validation_la = if record.needstype == 2
defined?(record.location.location_code) ? record.location.location_code : nil
else
record.la
end
rent_range = LaRentRange.find_by(start_year: collection_year, la: validation_la, beds: validation_beds, lettype: record.lettype)
if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? && record.period.present?
if record.weekly_value(record["brent"]) < rent_range.hard_min
@ -206,7 +207,7 @@ private
record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.below_hard_min")
record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.below_hard_min")
record.errors.add :period, I18n.t("validations.financial.brent.period.below_hard_min")
else
elsif !(record.needstype == 1 && record.beds > max_beds_in_rent_ranges)
record.errors.add :brent, I18n.t("validations.financial.brent.above_hard_max")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max")
record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max")

7
app/models/validations/soft_validations.rb

@ -36,7 +36,12 @@ module Validations::SoftValidations
return unless brent && weekly_value(brent) && startdate
rent_range = LaRentRange.find_by(start_year: collection_start_year, la: validation_la, beds: validation_beds, lettype: get_lettype)
rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)
max_beds_in_rent_ranges = 4
if beds > max_beds_in_rent_ranges
rent_range.present? && weekly_value(brent) > rent_range.soft_max
else
rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)
end
end
(1..8).each do |person_num|

Loading…
Cancel
Save