From e58ed1c09ccae971f330a70e20b9e38d3f080624 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 7 Jan 2022 12:23:22 +0000 Subject: [PATCH] Income frequency is derived rather than asked --- app/models/case_log.rb | 14 +++++++++++--- config/forms/2021_2022.json | 15 +++------------ spec/factories/case_log.rb | 1 - spec/fixtures/complete_case_log.json | 1 - spec/models/case_log_spec.rb | 11 +++++++++++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 95ab75489..61e60b984 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -132,7 +132,7 @@ class CaseLog < ApplicationRecord enum la_known: POLAR, _suffix: true enum net_income_known: NET_INCOME_KNOWN, _suffix: true - AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype is_la_inferred totchild totelder totadult].freeze + AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype is_la_inferred totchild totelder totadult incfreq].freeze OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze @@ -215,7 +215,16 @@ private self.month = startdate.month self.year = startdate.year end - self.incref = 1 if net_income_known == "Tenant prefers not to say" + case net_income_known + when "Yes – the household has a weekly income" + self.incfreq = "Weekly" + when "Yes – the household has a monthly income" + self.incfreq = "Monthly" + when "Yes – the household has a yearly income" + self.incfreq = "Yearly" + when "Tenant prefers not to say" + self.incref = 1 + end self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? self.renttype = RENT_TYPE_MAPPING[rent_type] self.lettype = "#{renttype} #{needstype} #{owning_organisation['Org type']}" if renttype.present? && needstype.present? && owning_organisation["Org type"].present? @@ -318,7 +327,6 @@ private if net_income_known == "Tenant prefers not to say" dynamically_not_required << "earnings" - dynamically_not_required << "incfreq" else dynamically_not_required << "incref" end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 054825ed9..4479a06a3 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1832,18 +1832,9 @@ "hint_text": "", "type": "numeric", "min": 0, - "step": "1" - }, - "incfreq": { - "check_answer_label": "Income Frequency", - "header": "How often do they receive this income?", - "hint_text": "", - "type": "radio", - "answer_options": { - "0": "Weekly", - "1": "Monthly", - "2": "Yearly" - } + "step": "1", + "prefix": "£", + "suffix": "" } }, "soft_validations": { diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 2c7d4ef0a..8a07b981c 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -71,7 +71,6 @@ FactoryBot.define do offered { 2 } wchair { "Yes" } earnings { 68 } - incfreq { "Weekly" } benefits { "Some" } period { "Fortnightly" } brent { 200 } diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index b55aadba9..1ed4d5206 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -76,7 +76,6 @@ "wchair": "Yes", "net_income_known": "Yes – the household has a weekly income", "earnings": 0, - "incfreq": null, "benefits": "Some", "hb": "Universal Credit with housing element, but not Housing Benefit", "period": "Fortnightly", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 609c751b2..88715b3ae 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1167,6 +1167,17 @@ RSpec.describe Form, type: :model do end end + context "net_income" do + it "infers the income frequency" do + case_log.update!(net_income_known: "Yes – the household has a weekly income") + expect(case_log.reload.incfreq).to eq("Weekly") + case_log.update!(net_income_known: "Yes – the household has a monthly income") + expect(case_log.reload.incfreq).to eq("Monthly") + case_log.update!(net_income_known: "Yes – the household has a yearly income") + expect(case_log.reload.incfreq).to eq("Yearly") + end + end + context "household members derived vars" do let!(:household_case_log) do CaseLog.create({