diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 635ad8af7..3b891bbb4 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -444,21 +444,13 @@ class LettingsLog < Log 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 - soft_min = LaRentRange.find_by(start_year: collection_start_year, la: validation_la, beds: validation_beds, lettype:).soft_min + soft_min = LaRentRange.find_by(start_year: collection_start_year, 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 - soft_max = LaRentRange.find_by(start_year: collection_start_year, la: validation_la, beds: validation_beds, lettype:).soft_max + soft_max = LaRentRange.find_by(start_year: collection_start_year, 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/financial_validations.rb b/app/models/validations/financial_validations.rb index 8f76275af..7688a65b1 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -188,13 +188,8 @@ private 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) + rent_range = LaRentRange.find_by(start_year: collection_year, la: record.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 @@ -207,7 +202,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") - elsif !(record.needstype == 1 && record.beds > max_beds_in_rent_ranges) + elsif !(record.beds.present? && 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 f01c8ed95..d974b6e36 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -28,14 +28,14 @@ module Validations::SoftValidations def rent_in_soft_min_range? 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 = LaRentRange.find_by(start_year: collection_start_year, 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 - rent_range = LaRentRange.find_by(start_year: collection_start_year, la: validation_la, beds: validation_beds, lettype: get_lettype) + rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds: validation_beds, lettype: get_lettype) max_beds_in_rent_ranges = 4 if beds.present? && beds > max_beds_in_rent_ranges rent_range.present? && weekly_value(brent) > rent_range.soft_max