Browse Source

Income frequency is derived rather than asked

pull/198/head
baarkerlounger 3 years ago
parent
commit
e58ed1c09c
  1. 14
      app/models/case_log.rb
  2. 15
      config/forms/2021_2022.json
  3. 1
      spec/factories/case_log.rb
  4. 1
      spec/fixtures/complete_case_log.json
  5. 11
      spec/models/case_log_spec.rb

14
app/models/case_log.rb

@ -132,7 +132,7 @@ class CaseLog < ApplicationRecord
enum la_known: POLAR, _suffix: true enum la_known: POLAR, _suffix: true
enum net_income_known: NET_INCOME_KNOWN, _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 OPTIONAL_FIELDS = %w[postcode_known
la_known la_known
first_time_property_let_as_social_housing].freeze first_time_property_let_as_social_housing].freeze
@ -215,7 +215,16 @@ private
self.month = startdate.month self.month = startdate.month
self.year = startdate.year self.year = startdate.year
end 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.hhmemb = other_hhmemb + 1 if other_hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type] 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? 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" if net_income_known == "Tenant prefers not to say"
dynamically_not_required << "earnings" dynamically_not_required << "earnings"
dynamically_not_required << "incfreq"
else else
dynamically_not_required << "incref" dynamically_not_required << "incref"
end end

15
config/forms/2021_2022.json

@ -1832,18 +1832,9 @@
"hint_text": "", "hint_text": "",
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"step": "1" "step": "1",
}, "prefix": "£",
"incfreq": { "suffix": ""
"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"
}
} }
}, },
"soft_validations": { "soft_validations": {

1
spec/factories/case_log.rb

@ -71,7 +71,6 @@ FactoryBot.define do
offered { 2 } offered { 2 }
wchair { "Yes" } wchair { "Yes" }
earnings { 68 } earnings { 68 }
incfreq { "Weekly" }
benefits { "Some" } benefits { "Some" }
period { "Fortnightly" } period { "Fortnightly" }
brent { 200 } brent { 200 }

1
spec/fixtures/complete_case_log.json vendored

@ -76,7 +76,6 @@
"wchair": "Yes", "wchair": "Yes",
"net_income_known": "Yes – the household has a weekly income", "net_income_known": "Yes – the household has a weekly income",
"earnings": 0, "earnings": 0,
"incfreq": null,
"benefits": "Some", "benefits": "Some",
"hb": "Universal Credit with housing element, but not Housing Benefit", "hb": "Universal Credit with housing element, but not Housing Benefit",
"period": "Fortnightly", "period": "Fortnightly",

11
spec/models/case_log_spec.rb

@ -1167,6 +1167,17 @@ RSpec.describe Form, type: :model do
end end
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 context "household members derived vars" do
let!(:household_case_log) do let!(:household_case_log) do
CaseLog.create({ CaseLog.create({

Loading…
Cancel
Save