Browse Source

CLDC-4352: refactoring

pull/3332/head
Nat Dean-Lewis 2 weeks ago
parent
commit
fa0751b144
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 3
      app/models/lettings_log.rb
  3. 8
      app/models/log.rb
  4. 1
      app/models/sales_log.rb
  5. 4
      app/models/validations/financial_validations.rb
  6. 35
      app/models/validations/soft_validations.rb

2
app/models/derived_variables/lettings_log_variables.rb

@ -339,7 +339,7 @@ private
def infer_only_partner!(partner_number) def infer_only_partner!(partner_number)
return unless hhmemb return unless hhmemb
(2..[hhmemb, 8].min).each do |i| (2..people_with_details).each do |i|
next if i == partner_number next if i == partner_number
if ["P", nil].include?(public_send("relat#{i}")) if ["P", nil].include?(public_send("relat#{i}"))

3
app/models/lettings_log.rb

@ -191,6 +191,7 @@ class LettingsLog < Log
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 11 => 51, 1 => 52, 10 => 53 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 11 => 51, 1 => 52, 10 => 53 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 sexrab1 ecstat1 tcharge household_charge chcharge].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 sexrab1 ecstat1 tcharge household_charge chcharge].freeze
MAX_PEOPLE_WITH_DETAILS = 8
RENT_TYPE = { RENT_TYPE = {
social_rent: 0, social_rent: 0,
affordable_rent: 1, affordable_rent: 1,
@ -284,7 +285,7 @@ class LettingsLog < Log
range = ALLOWED_INCOME_RANGES[ecstat1].clone range = ALLOWED_INCOME_RANGES[ecstat1].clone
if hhmemb > 1 if hhmemb > 1
(2..[hhmemb, 8].min).each do |person_index| (2..people_with_details).each do |person_index|
ecstat = self["ecstat#{person_index}"] ecstat = self["ecstat#{person_index}"]
if ecstat.nil? if ecstat.nil?

8
app/models/log.rb

@ -204,6 +204,14 @@ class Log < ApplicationRecord
false false
end end
def people_with_details
[hhmemb || max_people_with_details, max_people_with_details].min
end
def max_people_with_details
self.class::MAX_PEOPLE_WITH_DETAILS
end
def ethnic_refused? def ethnic_refused?
ethnic_group == 17 ethnic_group == 17
end end

1
app/models/sales_log.rb

@ -104,6 +104,7 @@ class SalesLog < Log
OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze
DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 sexrab1 ecstat1 postcode_full uprn address_line1].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 sexrab1 ecstat1 postcode_full uprn address_line1].freeze
MAX_PEOPLE_WITH_DETAILS = 6
def lettings? def lettings?
false false

4
app/models/validations/financial_validations.rb

@ -41,7 +41,7 @@ module Validations::FinancialValidations
:over_hard_max, :over_hard_max,
message: I18n.t("validations.lettings.financial.hhmemb.earnings_over_hard_max", earnings: format_as_currency(record.earnings), frequency:), message: I18n.t("validations.lettings.financial.hhmemb.earnings_over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
) )
(1..[record.hhmemb, 8].min).each do |n| (1..record.people_with_details).each do |n|
record.errors.add( record.errors.add(
"ecstat#{n}", "ecstat#{n}",
:over_hard_max, :over_hard_max,
@ -70,7 +70,7 @@ module Validations::FinancialValidations
:under_hard_min, :under_hard_min,
message: I18n.t("validations.lettings.financial.hhmemb.earnings_under_hard_min", earnings: format_as_currency(record.earnings), frequency:), message: I18n.t("validations.lettings.financial.hhmemb.earnings_under_hard_min", earnings: format_as_currency(record.earnings), frequency:),
) )
(1..[record.hhmemb, 8].min).each do |n| (1..record.people_with_details).each do |n|
record.errors.add( record.errors.add(
"ecstat#{n}", "ecstat#{n}",
:under_hard_min, :under_hard_min,

35
app/models/validations/soft_validations.rb

@ -208,8 +208,7 @@ module Validations::SoftValidations
def multiple_partners? def multiple_partners?
return unless hhmemb return unless hhmemb
max_person_with_details = sales? ? [hhmemb, 6].min : [hhmemb, 8].min (2..people_with_details).many? { |n| public_send("relat#{n}") == "P" }
(2..max_person_with_details).many? { |n| public_send("relat#{n}") == "P" }
end end
def at_least_one_working_situation_is_sickness_and_household_sickness_is_no? def at_least_one_working_situation_is_sickness_and_household_sickness_is_no?
@ -219,22 +218,18 @@ module Validations::SoftValidations
private private
def all_tenants_age_and_gender_information_completed? def all_tenants_age_and_gender_information_completed?
return false if hhmemb.present? && hhmemb > 8 return false if hhmemb.present? && hhmemb > max_people_with_details
return false unless all_tenants_gender_information_completed? return false unless all_tenants_gender_information_completed?
person_count = hhmemb || 8 (1..people_with_details).all? do |n|
(1..person_count).all? do |n|
public_send("age#{n}").present? && public_send("age#{n}_known").present? && public_send("age#{n}_known").zero? public_send("age#{n}").present? && public_send("age#{n}_known").present? && public_send("age#{n}_known").zero?
end end
end end
def all_tenants_gender_information_completed? def all_tenants_gender_information_completed?
return false if hhmemb.present? && hhmemb > 8 return false if hhmemb.present? && hhmemb > max_people_with_details
person_count = hhmemb || 8
(1..person_count).all? do |n| (1..people_with_details).all? do |n|
tenant_gender_information_completed?(n) tenant_gender_information_completed?(n)
end end
end end
@ -258,27 +253,21 @@ private
end end
def any_non_male_in_expected_pregnancy_age_range(min, max) def any_non_male_in_expected_pregnancy_age_range(min, max)
max_person_with_details = [hhmemb || 8, 8].min (1..people_with_details).any? do |n|
(1..max_person_with_details).any? do |n|
person_in_expected_pregnancy_age_range(n, min, max) && person_is_non_male(n) person_in_expected_pregnancy_age_range(n, min, max) && person_is_non_male(n)
end end
end end
def non_males_in_the_household? def non_males_in_the_household?
max_person_with_details = [hhmemb || 8, 8].min (1..people_with_details).any? do |n|
(1..max_person_with_details).any? do |n|
person_is_non_male(n) person_is_non_male(n)
end end
end end
def all_male_tenants_in_the_household? def all_male_tenants_in_the_household?
return false if hhmemb.present? && hhmemb > 8 return false if hhmemb.present? && hhmemb > max_people_with_details
person_count = hhmemb || 8 (1..people_with_details).all? do |n|
(1..person_count).all? do |n|
person_is_male(n) person_is_male(n)
end end
end end
@ -344,11 +333,7 @@ private
end end
def at_least_one_person_working_situation_is_illness? def at_least_one_person_working_situation_is_illness?
return if hhmemb.present? && hhmemb > 8 (1..people_with_details).any? { |n| public_send("ecstat#{n}") == 8 }
person_count = hhmemb || 8
(1..person_count).any? { |n| public_send("ecstat#{n}") == 8 }
end end
def no_one_in_household_with_illness? def no_one_in_household_with_illness?

Loading…
Cancel
Save