Browse Source

Derive Weekly shortfall value

pull/385/head
baarkerlounger 3 years ago
parent
commit
c0efefe645
  1. 29
      app/models/case_log.rb
  2. 9
      app/models/validations/financial_validations.rb
  3. 261
      spec/models/case_log_spec.rb

29
app/models/case_log.rb

@ -239,6 +239,30 @@ class CaseLog < ApplicationRecord
reason == 1 reason == 1
end end
def receives_housing_benefit_only?
hb == 1
end
def receives_housing_benefit_and_universal_credit?
hb == 8
end
def receives_uc_with_housing_element_excl_housing_benefit?
hb == 6
end
def receives_no_benefits?
hb == 9
end
def receives_universal_credit_but_no_housing_benefit?
hb == 7
end
def benefits_unknown?
hb == 3
end
private private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new
@ -327,6 +351,11 @@ private
self.wtcharge = weekly_value(tcharge) if tcharge.present? self.wtcharge = weekly_value(tcharge) if tcharge.present?
end end
self.has_benefits = get_has_benefits self.has_benefits = get_has_benefits
if tshortfall && (receives_housing_benefit_only? ||
receives_housing_benefit_and_universal_credit? ||
receives_uc_with_housing_element_excl_housing_benefit?)
self.wtshortfall = weekly_value(tshortfall)
end
self.nocharge = household_charge&.zero? ? 1 : 0 self.nocharge = household_charge&.zero? ? 1 : 0
self.underoccupation_benefitcap = 3 if renewal == 1 && year == 2021 self.underoccupation_benefitcap = 3 if renewal == 1 && year == 2021
self.ethnic = ethnic || ethnic_group self.ethnic = ethnic || ethnic_group

9
app/models/validations/financial_validations.rb

@ -51,11 +51,10 @@ module Validations::FinancialValidations
end end
def validate_tshortfall(record) def validate_tshortfall(record)
hb_donotknow = record.hb == 3 if record.has_hbrentshortfall? &&
hb_none = record.hb == 9 (record.benefits_unknown? ||
hb_uc_no_hb = record.hb == 7 record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?)
if record.has_hbrentshortfall? && (hb_donotknow || hb_none || hb_uc_no_hb)
record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end end
end end

261
spec/models/case_log_spec.rb

@ -334,6 +334,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(50.0) expect(case_log.wtcharge).to eq(50.0)
expect(record_from_db["wtcharge"]).to eq(50.0) expect(record_from_db["wtcharge"]).to eq(50.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 0, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 0, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 0, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0)
end
end
end
end end
context "when rent is paid every 4 weeks" do context "when rent is paid every 4 weeks" do
@ -371,6 +400,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(30.0) expect(case_log.wtcharge).to eq(30.0)
expect(record_from_db["wtcharge"]).to eq(30.0) expect(record_from_db["wtcharge"]).to eq(30.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 1, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 1, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 1, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
end
end end
context "when rent is paid every calendar month" do context "when rent is paid every calendar month" do
@ -408,6 +466,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(30.0) expect(case_log.wtcharge).to eq(30.0)
expect(record_from_db["wtcharge"]).to eq(30.0) expect(record_from_db["wtcharge"]).to eq(30.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 2, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 2, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 2, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
end
end end
context "when rent is paid weekly for 50 weeks" do context "when rent is paid weekly for 50 weeks" do
@ -445,6 +532,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(125.0) expect(case_log.wtcharge).to eq(125.0)
expect(record_from_db["wtcharge"]).to eq(125.0) expect(record_from_db["wtcharge"]).to eq(125.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 3, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 3, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 3, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0)
end
end
end
end end
context "when rent is paid weekly for 49 weeks" do context "when rent is paid weekly for 49 weeks" do
@ -482,6 +598,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(122.5) expect(case_log.wtcharge).to eq(122.5)
expect(record_from_db["wtcharge"]).to eq(122.5) expect(record_from_db["wtcharge"]).to eq(122.5)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5)
end
end
end
end end
context "when rent is paid weekly for 48 weeks" do context "when rent is paid weekly for 48 weeks" do
@ -519,6 +664,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(120.0) expect(case_log.wtcharge).to eq(120.0)
expect(record_from_db["wtcharge"]).to eq(120.0) expect(record_from_db["wtcharge"]).to eq(120.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0)
end
end
end
end end
context "when rent is paid weekly for 47 weeks" do context "when rent is paid weekly for 47 weeks" do
@ -556,6 +730,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(117.5) expect(case_log.wtcharge).to eq(117.5)
expect(record_from_db["wtcharge"]).to eq(117.5) expect(record_from_db["wtcharge"]).to eq(117.5)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5)
end
end
end
end end
context "when rent is paid weekly for 46 weeks" do context "when rent is paid weekly for 46 weeks" do
@ -593,6 +796,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(115.0) expect(case_log.wtcharge).to eq(115.0)
expect(record_from_db["wtcharge"]).to eq(115.0) expect(record_from_db["wtcharge"]).to eq(115.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0)
end
end
end
end end
context "when rent is paid weekly for 52 weeks" do context "when rent is paid weekly for 52 weeks" do
@ -630,6 +862,35 @@ RSpec.describe CaseLog do
expect(case_log.wtcharge).to eq(130.0) expect(case_log.wtcharge).to eq(130.0)
expect(record_from_db["wtcharge"]).to eq(130.0) expect(record_from_db["wtcharge"]).to eq(130.0)
end end
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0)
end
end
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0)
end
end
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0)
end
end
end
end end
end end

Loading…
Cancel
Save