diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 23d46c4c5..d87560de9 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -435,35 +435,29 @@ class LettingsLog < Log Csv::LettingsLogCsvService.new(user).to_csv end + def validation_beds + if needstype == 2 + 0 + else + beds.nil? ? nil : [beds, 4].min + end + end + + def validation_la + if needstype == 2 + defined?(location.location_code) ? location.location_code : nil + else + la + end + end + def soft_min_for_period - beds = if needstype == 2 - 0 - else - self.beds.nil? ? nil : [self.beds, 4].min - end - la = if needstype == 2 - defined?(location.location_code) ? location.location_code : nil - else - self.la - end - - soft_min = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_min + soft_min = LaRentRange.find_by(start_year: collection_start_year, la: validation_la, beds: validation_beds, lettype:).soft_min "#{soft_value_for_period(soft_min)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}" end def soft_max_for_period - beds = if needstype == 2 - 0 - else - self.beds.nil? ? nil : [self.beds, 4].min - end - la = if needstype == 2 - defined?(location.location_code) ? location.location_code : nil - else - self.la - end - - soft_max = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_max + soft_max = LaRentRange.find_by(start_year: collection_start_year, la: validation_la, beds: validation_beds, lettype:).soft_max "#{soft_value_for_period(soft_max)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}" end diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 6ee9398d7..78699be8d 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -28,36 +28,14 @@ module Validations::SoftValidations def rent_in_soft_min_range? return unless brent && weekly_value(brent) && startdate - beds = if needstype == 2 - 0 - else - self.beds.nil? ? nil : [self.beds, 4].min - end - la = if needstype == 2 - defined?(location.location_code) ? location.location_code : nil - else - self.la - end - - rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype: get_lettype) + 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.hard_min, rent_range.soft_min) end def rent_in_soft_max_range? return unless brent && weekly_value(brent) && startdate - beds = if needstype == 2 - 0 - else - self.beds.nil? ? nil : [self.beds, 4].min - end - la = if needstype == 2 - defined?(location.location_code) ? location.location_code : nil - else - self.la - end - - rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype: get_lettype) + 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) end