diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index d87560de9..635ad8af7 100644 --- a/app/models/lettings_log.rb +++ b/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 diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 1858d9c1f..8f76275af 100644 --- a/app/models/validations/financial_validations.rb +++ b/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") diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 78699be8d..11cd302a5 100644 --- a/app/models/validations/soft_validations.rb +++ b/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|