Browse Source

CLDC-1852 add weekly rent period and reorder options (#1507)

* add in a new option for the period question and reorder existing answer options

* ensure that the lettings log calculates values correctly that relate to the period

* ensure that depends on conditions related to period take account of the new option
relatedly create methods on LettingsLog to allow improved readability in these depends on conditions
refactor depends on conditions with these new method

* update the 22_23 json form to use the new option as well

* update tests to cover deriving variables that depend on period
update test fixture to allow this

* refactor some depends on and amend LEttingsLog method to improve readability

* remove forgotten focus in spec file found in linting check

* amend context descriptino in new tests

* refactor a couple more depends on for readability
pull/1556/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
9fb3bac389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/models/form/lettings/pages/care_home_weekly.rb
  2. 2
      app/models/form/lettings/pages/outstanding_amount.rb
  3. 6
      app/models/form/lettings/pages/rent_4_weekly.rb
  4. 6
      app/models/form/lettings/pages/rent_bi_weekly.rb
  5. 6
      app/models/form/lettings/pages/rent_monthly.rb
  6. 26
      app/models/form/lettings/pages/rent_weekly.rb
  7. 9
      app/models/form/lettings/questions/period.rb
  8. 1
      app/models/form/lettings/questions/tshortfall.rb
  9. 26
      app/models/lettings_log.rb
  10. 4
      app/models/validations/financial_validations.rb
  11. 201
      config/forms/2022_2023.json
  12. 19
      spec/fixtures/forms/2021_2022.json
  13. 81
      spec/models/lettings_log_spec.rb

14
app/models/form/lettings/pages/care_home_weekly.rb

@ -3,18 +3,8 @@ class Form::Lettings::Pages::CareHomeWeekly < ::Form::Page
super super
@id = "care_home_weekly" @id = "care_home_weekly"
@depends_on = [ @depends_on = [
{ "period" => 1, "needstype" => 2, "household_charge" => 0 }, { "rent_and_charges_paid_weekly?" => true, "is_supported_housing?" => true, "household_charge" => 0 },
{ "period" => 1, "needstype" => 2, "household_charge" => nil }, { "rent_and_charges_paid_weekly?" => true, "is_supported_housing?" => true, "household_charge" => nil },
{ "period" => 5, "needstype" => 2, "household_charge" => 0 },
{ "period" => 5, "needstype" => 2, "household_charge" => nil },
{ "period" => 6, "needstype" => 2, "household_charge" => 0 },
{ "period" => 6, "needstype" => 2, "household_charge" => nil },
{ "period" => 7, "needstype" => 2, "household_charge" => 0 },
{ "period" => 7, "needstype" => 2, "household_charge" => nil },
{ "period" => 8, "needstype" => 2, "household_charge" => 0 },
{ "period" => 8, "needstype" => 2, "household_charge" => nil },
{ "period" => 9, "needstype" => 2, "household_charge" => 0 },
{ "period" => 9, "needstype" => 2, "household_charge" => nil },
] ]
end end

2
app/models/form/lettings/pages/outstanding_amount.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::OutstandingAmount < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "outstanding_amount" @id = "outstanding_amount"
@depends_on = [{ "hb" => 1, "hbrentshortfall" => 1 }, { "hb" => 6, "hbrentshortfall" => 1 }] @depends_on = [{ "receives_housing_related_benefits?" => true, "has_housing_benefit_rent_shortfall?" => true }]
end end
def questions def questions

6
app/models/form/lettings/pages/rent_4_weekly.rb

@ -4,10 +4,8 @@ class Form::Lettings::Pages::Rent4Weekly < ::Form::Page
@id = "rent_4_weekly" @id = "rent_4_weekly"
@header = "Household rent and charges" @header = "Household rent and charges"
@depends_on = [ @depends_on = [
{ "household_charge" => 0, "period" => 3, "is_carehome" => 0 }, { "household_charge" => 0, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false },
{ "household_charge" => nil, "period" => 3, "is_carehome" => 0 }, { "household_charge" => nil, "rent_and_charges_paid_every_4_weeks?" => true, "is_carehome?" => false },
{ "household_charge" => 0, "period" => 3, "is_carehome" => nil },
{ "household_charge" => nil, "period" => 3, "is_carehome" => nil },
] ]
end end

6
app/models/form/lettings/pages/rent_bi_weekly.rb

@ -4,10 +4,8 @@ class Form::Lettings::Pages::RentBiWeekly < ::Form::Page
@id = "rent_bi_weekly" @id = "rent_bi_weekly"
@header = "Household rent and charges" @header = "Household rent and charges"
@depends_on = [ @depends_on = [
{ "household_charge" => 0, "period" => 2, "is_carehome" => 0 }, { "household_charge" => nil, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false },
{ "household_charge" => nil, "period" => 2, "is_carehome" => 0 }, { "household_charge" => 0, "rent_and_charges_paid_every_2_weeks?" => true, "is_carehome?" => false },
{ "household_charge" => 0, "period" => 2, "is_carehome" => nil },
{ "household_charge" => nil, "period" => 2, "is_carehome" => nil },
] ]
end end

6
app/models/form/lettings/pages/rent_monthly.rb

@ -4,10 +4,8 @@ class Form::Lettings::Pages::RentMonthly < ::Form::Page
@id = "rent_monthly" @id = "rent_monthly"
@header = "Household rent and charges" @header = "Household rent and charges"
@depends_on = [ @depends_on = [
{ "household_charge" => 0, "period" => 4, "is_carehome" => 0 }, { "household_charge" => nil, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false },
{ "household_charge" => nil, "period" => 4, "is_carehome" => 0 }, { "household_charge" => 0, "rent_and_charges_paid_monthly?" => true, "is_carehome?" => false },
{ "household_charge" => 0, "period" => 4, "is_carehome" => nil },
{ "household_charge" => nil, "period" => 4, "is_carehome" => nil },
] ]
end end

26
app/models/form/lettings/pages/rent_weekly.rb

@ -4,30 +4,8 @@ class Form::Lettings::Pages::RentWeekly < ::Form::Page
@id = "rent_weekly" @id = "rent_weekly"
@header = "Household rent and charges" @header = "Household rent and charges"
@depends_on = [ @depends_on = [
{ "period" => 1, "household_charge" => 0, "is_carehome" => 0 }, { "rent_and_charges_paid_weekly?" => true, "household_charge" => 0, "is_carehome?" => false },
{ "period" => 1, "household_charge" => nil, "is_carehome" => 0 }, { "rent_and_charges_paid_weekly?" => true, "household_charge" => nil, "is_carehome?" => false },
{ "period" => 5, "household_charge" => 0, "is_carehome" => 0 },
{ "period" => 5, "household_charge" => nil, "is_carehome" => 0 },
{ "period" => 6, "household_charge" => 0, "is_carehome" => 0 },
{ "period" => 6, "household_charge" => nil, "is_carehome" => 0 },
{ "period" => 7, "household_charge" => 0, "is_carehome" => 0 },
{ "period" => 7, "household_charge" => nil, "is_carehome" => 0 },
{ "period" => 8, "household_charge" => 0, "is_carehome" => 0 },
{ "period" => 8, "household_charge" => nil, "is_carehome" => 0 },
{ "period" => 9, "household_charge" => 0, "is_carehome" => 0 },
{ "period" => 9, "household_charge" => nil, "is_carehome" => 0 },
{ "period" => 1, "household_charge" => 0, "is_carehome" => nil },
{ "period" => 1, "household_charge" => nil, "is_carehome" => nil },
{ "period" => 5, "household_charge" => 0, "is_carehome" => nil },
{ "period" => 5, "household_charge" => nil, "is_carehome" => nil },
{ "period" => 6, "household_charge" => 0, "is_carehome" => nil },
{ "period" => 6, "household_charge" => nil, "is_carehome" => nil },
{ "period" => 7, "household_charge" => 0, "is_carehome" => nil },
{ "period" => 7, "household_charge" => nil, "is_carehome" => nil },
{ "period" => 8, "household_charge" => 0, "is_carehome" => nil },
{ "period" => 8, "household_charge" => nil, "is_carehome" => nil },
{ "period" => 9, "household_charge" => 0, "is_carehome" => nil },
{ "period" => 9, "household_charge" => nil, "is_carehome" => nil },
] ]
end end

9
app/models/form/lettings/questions/period.rb

@ -15,11 +15,12 @@ class Form::Lettings::Questions::Period < ::Form::Question
"2" => { "value" => "Every 2 weeks" }, "2" => { "value" => "Every 2 weeks" },
"3" => { "value" => "Every 4 weeks" }, "3" => { "value" => "Every 4 weeks" },
"4" => { "value" => "Every calendar month" }, "4" => { "value" => "Every calendar month" },
"5" => { "value" => "Weekly for 50 weeks" },
"6" => { "value" => "Weekly for 49 weeks" },
"7" => { "value" => "Weekly for 48 weeks" },
"8" => { "value" => "Weekly for 47 weeks" },
"9" => { "value" => "Weekly for 46 weeks" }, "9" => { "value" => "Weekly for 46 weeks" },
"8" => { "value" => "Weekly for 47 weeks" },
"7" => { "value" => "Weekly for 48 weeks" },
"6" => { "value" => "Weekly for 49 weeks" },
"5" => { "value" => "Weekly for 50 weeks" },
"1" => { "value" => "Weekly for 52 weeks" }, "1" => { "value" => "Weekly for 52 weeks" },
"10" => { "value" => "Weekly for 53 weeks" },
}.freeze }.freeze
end end

1
app/models/form/lettings/questions/tshortfall.rb

@ -20,6 +20,7 @@ class Form::Lettings::Questions::Tshortfall < ::Form::Question
{ "label" => " every week for 47 weeks", "depends_on" => { "period" => 8 } }, { "label" => " every week for 47 weeks", "depends_on" => { "period" => 8 } },
{ "label" => " every week for 46 weeks", "depends_on" => { "period" => 9 } }, { "label" => " every week for 46 weeks", "depends_on" => { "period" => 9 } },
{ "label" => " every week for 52 weeks", "depends_on" => { "period" => 1 } }, { "label" => " every week for 52 weeks", "depends_on" => { "period" => 1 } },
{ "label" => " every week for 53 weeks", "depends_on" => { "period" => 10 } },
] ]
@question_number = 100 @question_number = 100
end end

26
app/models/lettings_log.rb

@ -58,7 +58,7 @@ class LettingsLog < Log
OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode chcharge].freeze OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode chcharge].freeze
RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
@ -203,7 +203,7 @@ class LettingsLog < Log
needstype == 2 needstype == 2
end end
def has_hbrentshortfall? def has_housing_benefit_rent_shortfall?
# 1: Yes # 1: Yes
hbrentshortfall == 1 hbrentshortfall == 1
end end
@ -496,7 +496,27 @@ class LettingsLog < Log
end end
def care_home_charge_expected_not_provided? def care_home_charge_expected_not_provided?
is_carehome == 1 && chcharge.blank? is_carehome? && chcharge.blank?
end
def rent_and_charges_paid_weekly?
[1, 5, 6, 7, 8, 9, 10].include? period
end
def rent_and_charges_paid_every_4_weeks?
period == 3
end
def rent_and_charges_paid_every_2_weeks?
period == 2
end
def rent_and_charges_paid_monthly?
period == 4
end
def is_carehome?
is_carehome == 1
end end
private private

4
app/models/validations/financial_validations.rb

@ -4,7 +4,7 @@ module Validations::FinancialValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save # Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record) def validate_outstanding_rent_amount(record)
if !record.has_hbrentshortfall? && record.tshortfall.present? if !record.has_housing_benefit_rent_shortfall? && record.tshortfall.present?
record.errors.add :tshortfall, :no_outstanding_charges, message: I18n.t("validations.financial.tshortfall.outstanding_amount_not_required") record.errors.add :tshortfall, :no_outstanding_charges, message: I18n.t("validations.financial.tshortfall.outstanding_amount_not_required")
end end
end end
@ -69,7 +69,7 @@ module Validations::FinancialValidations
end end
def validate_tshortfall(record) def validate_tshortfall(record)
if record.has_hbrentshortfall? && no_known_benefits?(record) if record.has_housing_benefit_rent_shortfall? && no_known_benefits?(record)
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

201
config/forms/2022_2023.json

@ -7492,23 +7492,26 @@
"4": { "4": {
"value": "Every calendar month" "value": "Every calendar month"
}, },
"5": { "9": {
"value": "Weekly for 50 weeks" "value": "Weekly for 46 weeks"
}, },
"6": { "8": {
"value": "Weekly for 49 weeks" "value": "Weekly for 47 weeks"
}, },
"7": { "7": {
"value": "Weekly for 48 weeks" "value": "Weekly for 48 weeks"
}, },
"8": { "6": {
"value": "Weekly for 47 weeks" "value": "Weekly for 49 weeks"
}, },
"9": { "5": {
"value": "Weekly for 46 weeks" "value": "Weekly for 50 weeks"
}, },
"1": { "1": {
"value": "Weekly for 52 weeks" "value": "Weekly for 52 weeks"
},
"10": {
"value": "Weekly for 53 weeks"
} }
} }
} }
@ -7558,63 +7561,13 @@
}, },
"depends_on": [ "depends_on": [
{ {
"period": 1, "rent_and_charges_paid_weekly?": true,
"needstype": 2, "is_supported_housing?": true,
"household_charge": 0 "household_charge": 0
}, },
{ {
"period": 1, "rent_and_charges_paid_weekly?": true,
"needstype": 2, "is_supported_housing?": true,
"household_charge": null
},
{
"period": 5,
"needstype": 2,
"household_charge": 0
},
{
"period": 5,
"needstype": 2,
"household_charge": null
},
{
"period": 6,
"needstype": 2,
"household_charge": 0
},
{
"period": 6,
"needstype": 2,
"household_charge": null
},
{
"period": 7,
"needstype": 2,
"household_charge": 0
},
{
"period": 7,
"needstype": 2,
"household_charge": null
},
{
"period": 8,
"needstype": 2,
"household_charge": 0
},
{
"period": 8,
"needstype": 2,
"household_charge": null
},
{
"period": 9,
"needstype": 2,
"household_charge": 0
},
{
"period": 9,
"needstype": 2,
"household_charge": null "household_charge": null
} }
] ]
@ -7898,124 +7851,14 @@
}, },
"depends_on": [ "depends_on": [
{ {
"period": 1, "rent_and_charges_paid_weekly?": true,
"household_charge": 0,
"is_carehome": 0
},
{
"period": 1,
"household_charge": null,
"is_carehome": 0
},
{
"period": 5,
"household_charge": 0,
"is_carehome": 0
},
{
"period": 5,
"household_charge": null,
"is_carehome": 0
},
{
"period": 6,
"household_charge": 0,
"is_carehome": 0
},
{
"period": 6,
"household_charge": null,
"is_carehome": 0
},
{
"period": 7,
"household_charge": 0,
"is_carehome": 0
},
{
"period": 7,
"household_charge": null,
"is_carehome": 0
},
{
"period": 8,
"household_charge": 0, "household_charge": 0,
"is_carehome": 0 "is_carehome?": false
}, },
{ {
"period": 8, "rent_and_charges_paid_weekly?": true,
"household_charge": null, "household_charge": null,
"is_carehome": 0 "is_carehome?": false
},
{
"period": 9,
"household_charge": 0,
"is_carehome": 0
},
{
"period": 9,
"household_charge": null,
"is_carehome": 0
},
{
"period": 1,
"household_charge": 0,
"is_carehome": null
},
{
"period": 1,
"household_charge": null,
"is_carehome": null
},
{
"period": 5,
"household_charge": 0,
"is_carehome": null
},
{
"period": 5,
"household_charge": null,
"is_carehome": null
},
{
"period": 6,
"household_charge": 0,
"is_carehome": null
},
{
"period": 6,
"household_charge": null,
"is_carehome": null
},
{
"period": 7,
"household_charge": 0,
"is_carehome": null
},
{
"period": 7,
"household_charge": null,
"is_carehome": null
},
{
"period": 8,
"household_charge": 0,
"is_carehome": null
},
{
"period": 8,
"household_charge": null,
"is_carehome": null
},
{
"period": 9,
"household_charge": 0,
"is_carehome": null
},
{
"period": 9,
"household_charge": null,
"is_carehome": null
} }
] ]
}, },
@ -8602,6 +8445,12 @@
"depends_on": { "depends_on": {
"period": 1 "period": 1
} }
},
{
"label": " every week for 53 weeks",
"depends_on": {
"period": 10
}
} }
] ]
} }

19
spec/fixtures/forms/2021_2022.json vendored

@ -879,23 +879,26 @@
"4": { "4": {
"value": "Every calendar month" "value": "Every calendar month"
}, },
"5": { "9": {
"value": "Weekly for 50 weeks" "value": "Weekly for 46 weeks"
}, },
"6": { "8": {
"value": "Weekly for 49 weeks" "value": "Weekly for 47 weeks"
}, },
"7": { "7": {
"value": "Weekly for 48 weeks" "value": "Weekly for 48 weeks"
}, },
"8": { "6": {
"value": "Weekly for 47 weeks" "value": "Weekly for 49 weeks"
}, },
"9": { "5": {
"value": "Weekly for 46 weeks" "value": "Weekly for 50 weeks"
}, },
"1": { "1": {
"value": "Weekly for 52 weeks" "value": "Weekly for 52 weeks"
},
"10": {
"value": "Weekly for 53 weeks"
} }
} }
}, },

81
spec/models/lettings_log_spec.rb

@ -1079,6 +1079,87 @@ RSpec.describe LettingsLog do
expect(record_from_db["wtcharge"]).to eq(187.2) expect(record_from_db["wtcharge"]).to eq(187.2)
end end
end end
context "when rent is paid weekly for 53 weeks" do
it "correctly derives and saves weekly rent" do
lettings_log.update!(brent: 130, period: 10)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wrent).to eq(132.5)
expect(record_from_db["wrent"]).to eq(132.5)
end
it "correctly derives and saves weekly service charge" do
lettings_log.update!(scharge: 30, period: 10)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wscharge).to eq(30.58)
expect(record_from_db["wscharge"]).to eq(30.58)
end
it "correctly derives and saves weekly personal service charge" do
lettings_log.update!(pscharge: 30, period: 10)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wpschrge).to eq(30.58)
expect(record_from_db["wpschrge"]).to eq(30.58)
end
it "correctly derives and saves weekly support charge" do
lettings_log.update!(supcharg: 30, period: 10)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wsupchrg).to eq(30.58)
expect(record_from_db["wsupchrg"]).to eq(30.58)
end
it "correctly derives and saves weekly total charge" do
lettings_log.update!(tcharge: 30, period: 10)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wtcharge).to eq(30.58)
expect(record_from_db["wtcharge"]).to eq(30.58)
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
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 10, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wtshortfall).to eq(132.5)
expect(record_from_db["wtshortfall"]).to eq(132.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
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 10, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wtshortfall).to eq(132.5)
expect(record_from_db["wtshortfall"]).to eq(132.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
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 10, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wtshortfall).to eq(132.5)
expect(record_from_db["wtshortfall"]).to eq(132.5)
end
end
end
it "correctly derives floats" do
lettings_log.update!(supcharg: 30.12, pscharge: 25.13, scharge: 30.98, brent: 100.97, period: 10)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.wsupchrg).to eq(30.7)
expect(lettings_log.wpschrge).to eq(25.61)
expect(lettings_log.wscharge).to eq(31.58)
expect(lettings_log.wrent).to eq(102.91)
expect(lettings_log.wtcharge).to eq(190.8)
expect(record_from_db["wsupchrg"]).to eq(30.7)
expect(record_from_db["wpschrge"]).to eq(25.61)
expect(record_from_db["wscharge"]).to eq(31.58)
expect(record_from_db["wrent"]).to eq(102.91)
expect(record_from_db["wtcharge"]).to eq(190.8)
end
end
end end
context "when the owning organisation is a LA" do context "when the owning organisation is a LA" do

Loading…
Cancel
Save