Browse Source

Validate all relevant charges given for BU 2023

pull/2250/head
Kat 2 years ago
parent
commit
deb4633ef1
  1. 21
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  2. 1
      config/locales/en.yml
  3. 105
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

21
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -391,6 +391,7 @@ class BulkUpload::Lettings::Year2023::RowParser
validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate } validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate }
validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable } validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable }
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -854,6 +855,20 @@ private
end end
end end
def validate_all_charges_given
return if supported_housing? && field_125 == 1
{ field_128: "basic rent",
field_129: "service charge",
field_130: "personal service charge",
field_131: "support charge",
field_132: "total charge" }.each do |field, charge|
if public_send(field.to_sym).blank?
errors.add(field, I18n.t("validations.financial.charges.missing_charges", question: charge))
end
end
end
def setup_question?(question) def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question) log.form.setup_sections[0].subsections[0].questions.include?(question)
end end
@ -1192,7 +1207,7 @@ private
attributes["supcharg"] = field_131 attributes["supcharg"] = field_131
attributes["tcharge"] = field_132 attributes["tcharge"] = field_132
attributes["chcharge"] = field_127 attributes["chcharge"] = field_127
attributes["is_carehome"] = field_127.present? ? 1 : 0 attributes["is_carehome"] = is_carehome
attributes["household_charge"] = supported_housing? ? field_125 : nil attributes["household_charge"] = supported_housing? ? field_125 : nil
attributes["hbrentshortfall"] = field_133 attributes["hbrentshortfall"] = field_133
attributes["tshortfall_known"] = tshortfall_known attributes["tshortfall_known"] = tshortfall_known
@ -1574,4 +1589,8 @@ private
0 0
end end
end end
def is_carehome
field_127.present? ? 1 : 0
end
end end

1
config/locales/en.yml

@ -416,6 +416,7 @@ en:
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period" above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period"
charges: charges:
complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’" complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’"
missing_charges: "Please enter the %{question}. If there is no %{question}, please enter '0'."
tcharge: tcharge:
under_10: "Enter a total charge that is at least £10.00 per week" under_10: "Enter a total charge that is at least £10.00 per week"
rent_period: rent_period:

105
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -2294,19 +2294,76 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
describe "#chcharge" do describe "#chcharge" do
let(:attributes) { { bulk_upload:, field_127: "123.45" } } let(:attributes) { { bulk_upload:, field_127: "123.45", field_131: "123.45", field_130: "123.45", field_129: "123.45", field_128: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.chcharge).to eq(123.45) expect(parser.log.chcharge).to eq(123.45)
end end
it "sets is care home to yes" do
expect(parser.log.is_carehome).to eq(1)
end
it "clears any other given charges" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
end end
describe "#tcharge" do describe "#tcharge" do
let(:attributes) { { bulk_upload:, field_132: "123.45" } } let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: "123.45", field_128: "123.45", field_129: "123.45", field_130: "123.45", field_131: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.tcharge).to eq(123.45) expect(parser.log.tcharge).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: "123.45", field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to be_empty
expect(parser.errors[:field_129]).to be_empty
expect(parser.errors[:field_130]).to be_empty
expect(parser.errors[:field_131]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: nil, field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_129]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_130]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_131]).to eql(["Please enter the support charge. If there is no support charge, please enter '0'."])
end
end
end
end end
describe "#supcharg" do describe "#supcharg" do
@ -2315,6 +2372,50 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "sets value given" do it "sets value given" do
expect(parser.log.supcharg).to eq(123.45) expect(parser.log.supcharg).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_132: nil, field_127: "123.45", field_128: nil, field_129: nil, field_130: nil, field_131: "123.45" } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to be_empty
expect(parser.errors[:field_129]).to be_empty
expect(parser.errors[:field_130]).to be_empty
expect(parser.errors[:field_131]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: nil, field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_129]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_130]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_131]).to eql(["Please enter the support charge. If there is no support charge, please enter '0'."])
end
end
end
end end
describe "#pscharge" do describe "#pscharge" do

Loading…
Cancel
Save