diff --git a/app/models/case_log.rb b/app/models/case_log.rb
index faf8a702f..09cac5d5a 100644
--- a/app/models/case_log.rb
+++ b/app/models/case_log.rb
@@ -259,6 +259,11 @@ class CaseLog < ApplicationRecord
hb == 7
end
+ def receives_housing_related_benefits?
+ receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? ||
+ receives_housing_benefit_and_universal_credit?
+ end
+
def benefits_unknown?
hb == 3
end
@@ -351,11 +356,9 @@ private
self.wtcharge = weekly_value(tcharge) if tcharge.present?
end
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.wtshortfall = if tshortfall && receives_housing_related_benefits?
+ weekly_value(tshortfall)
+ end
self.nocharge = household_charge&.zero? ? 1 : 0
self.underoccupation_benefitcap = 3 if renewal == 1 && year == 2021
self.ethnic = ethnic || ethnic_group
diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml
index 63cfe21fe..478f3d90f 100644
--- a/spec/fixtures/exports/case_logs.xml
+++ b/spec/fixtures/exports/case_logs.xml
@@ -165,6 +165,6 @@
20.0
17.5
162.5
-
+ 6.0
diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb
index ab9e44a90..be636dfa8 100644
--- a/spec/models/case_log_spec.rb
+++ b/spec/models/case_log_spec.rb
@@ -299,6 +299,15 @@ RSpec.describe CaseLog do
end
end
+ context "when the tenant is not in receipt of applicable benefits" do
+ it "correctly resets total shortfall" do
+ case_log.update!(wtshortfall: 100, hb: 9)
+ 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 be_nil
+ expect(record_from_db["wtshortfall"]).to be_nil
+ end
+ end
+
context "when rent is paid bi-weekly" do
it "correctly derives and saves weekly rent" do
case_log.update!(brent: 100, period: 0)