Browse Source

Reset weekly total shortfall when not applicable

pull/385/head
baarkerlounger 3 years ago
parent
commit
3c598d4962
  1. 11
      app/models/case_log.rb
  2. 2
      spec/fixtures/exports/case_logs.xml
  3. 9
      spec/models/case_log_spec.rb

11
app/models/case_log.rb

@ -259,6 +259,11 @@ class CaseLog < ApplicationRecord
hb == 7 hb == 7
end 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? def benefits_unknown?
hb == 3 hb == 3
end end
@ -351,10 +356,8 @@ 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? || self.wtshortfall = if tshortfall && receives_housing_related_benefits?
receives_housing_benefit_and_universal_credit? || weekly_value(tshortfall)
receives_uc_with_housing_element_excl_housing_benefit?)
self.wtshortfall = weekly_value(tshortfall)
end 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

2
spec/fixtures/exports/case_logs.xml vendored

@ -165,6 +165,6 @@
<wpschrge>20.0</wpschrge> <wpschrge>20.0</wpschrge>
<wsupchrg>17.5</wsupchrg> <wsupchrg>17.5</wsupchrg>
<wtcharge>162.5</wtcharge> <wtcharge>162.5</wtcharge>
<wtshortfall/> <wtshortfall>6.0</wtshortfall>
</form> </form>
</forms> </forms>

9
spec/models/case_log_spec.rb

@ -299,6 +299,15 @@ RSpec.describe CaseLog do
end end
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 context "when rent is paid bi-weekly" do
it "correctly derives and saves weekly rent" do it "correctly derives and saves weekly rent" do
case_log.update!(brent: 100, period: 0) case_log.update!(brent: 100, period: 0)

Loading…
Cancel
Save