Browse Source

feat: null coalescing and validations on changing las to one that invalidates rent in supported housing

pull/959/head
natdeanlewissoftwire 3 years ago
parent
commit
e3990eb328
  1. 12
      app/models/lettings_log.rb
  2. 6
      app/models/validations/financial_validations.rb
  3. 12
      app/models/validations/soft_validations.rb

12
app/models/lettings_log.rb

@ -437,7 +437,11 @@ class LettingsLog < Log
def soft_min_for_period def soft_min_for_period
beds = needstype == 2 ? 0 : [self.beds, 4].min beds = needstype == 2 ? 0 : [self.beds, 4].min
la = needstype == 2 ? Location.find(location_id).location_code : self.la la = if needstype == 2
defined?(self.location.location_code) ? self.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:, beds:, lettype:).soft_min
"#{soft_value_for_period(soft_min)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}" "#{soft_value_for_period(soft_min)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}"
@ -445,7 +449,11 @@ class LettingsLog < Log
def soft_max_for_period def soft_max_for_period
beds = needstype == 2 ? 0 : [self.beds, 4].min beds = needstype == 2 ? 0 : [self.beds, 4].min
la = needstype == 2 ? Location.find(location_id).location_code : self.la la = if needstype == 2
defined?(self.location.location_code) ? self.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:, beds:, lettype:).soft_max
"#{soft_value_for_period(soft_max)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}" "#{soft_value_for_period(soft_max)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}"

6
app/models/validations/financial_validations.rb

@ -183,7 +183,11 @@ private
collection_year = record.collection_start_year collection_year = record.collection_start_year
beds = record.needstype == 2 ? 0 : [record.beds, 4].min beds = record.needstype == 2 ? 0 : [record.beds, 4].min
la = record.needstype == 2 ? Location.find(record.location_id).location_code : record.la 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) rent_range = LaRentRange.find_by(start_year: collection_year, la:, beds:, lettype: record.lettype)

12
app/models/validations/soft_validations.rb

@ -29,7 +29,11 @@ module Validations::SoftValidations
return unless brent && weekly_value(brent) && startdate return unless brent && weekly_value(brent) && startdate
beds = needstype == 2 ? 0 : [self.beds, 4].min beds = needstype == 2 ? 0 : [self.beds, 4].min
la = needstype == 2 ? Location.find(location_id).location_code : self.la la = if needstype == 2
defined?(self.location.location_code) ? self.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:, beds:, lettype: get_lettype)
rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min) rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min)
@ -39,7 +43,11 @@ module Validations::SoftValidations
return unless brent && weekly_value(brent) && startdate return unless brent && weekly_value(brent) && startdate
beds = needstype == 2 ? 0 : [self.beds, 4].min beds = needstype == 2 ? 0 : [self.beds, 4].min
la = needstype == 2 ? Location.find(location_id).location_code : self.la la = if needstype == 2
defined?(self.location.location_code) ? self.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:, beds:, lettype: get_lettype)
rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max) rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)

Loading…
Cancel
Save