diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb
index ec217ca77..739649dd4 100644
--- a/app/models/validations/soft_validations.rb
+++ b/app/models/validations/soft_validations.rb
@@ -24,4 +24,18 @@ module Validations::SoftValidations
weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min)
end
+
+ def rent_in_soft_min_range?
+ return unless brent && weekly_value(brent) && startdate
+
+ rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:)
+ rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min)
+ end
+
+ def rent_in_soft_max_range?
+ return unless brent && weekly_value(brent) && startdate
+
+ rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:)
+ rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)
+ end
end
diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json
index 2903be295..6d8c269b3 100644
--- a/config/forms/2021_2022.json
+++ b/config/forms/2021_2022.json
@@ -5568,6 +5568,54 @@
}
]
},
+ "check_min_rent_amount": {
+ "depends_on": [{ "rent_in_soft_min_range?": true }],
+ "title_text": "Rent value is under the expected range",
+ "informative_text": {
+ "translation": "soft_validations.rent.min_max.hint_text",
+ "argument": ["brent"]
+ },
+ "questions": {
+ "rent_value_check": {
+ "check_answer_label": "Rent soft validation",
+ "hidden_in_check_answers": true,
+ "header": "Are you sure this is correct?",
+ "type": "interruption_screen",
+ "answer_options": {
+ "0": {
+ "value":"Yes"
+ },
+ "1": {
+ "value":"No"
+ }
+ }
+ }
+ }
+ },
+ "check_max_rent_amount": {
+ "depends_on": [{ "rent_in_soft_max_range?": true }],
+ "title_text": "Rent value is over the expected range",
+ "informative_text": {
+ "translation": "soft_validations.rent.min_max.hint_text",
+ "argument": ["brent"]
+ },
+ "questions": {
+ "rent_value_check": {
+ "check_answer_label": "Rent soft validation",
+ "hidden_in_check_answers": true,
+ "header": "Are you sure this is correct?",
+ "type": "interruption_screen",
+ "answer_options": {
+ "0": {
+ "value":"Yes"
+ },
+ "1": {
+ "value":"No"
+ }
+ }
+ }
+ }
+ },
"outstanding": {
"header": "",
"description": "",
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0f8227d20..a5696d1be 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -224,6 +224,9 @@ en:
message: "Net income is lower than expected based on the main tenant’s working situation. Are you sure this is correct?"
in_soft_max_range:
message: "Net income is higher than expected based on the main tenant’s working situation. Are you sure this is correct?"
+ rent:
+ min_max:
+ hint_text: "You have entered %{brent}"
devise:
two_factor_authentication:
success: "Two factor authentication successful."
diff --git a/db/migrate/20220328133331_add_rent_value_check.rb b/db/migrate/20220328133331_add_rent_value_check.rb
new file mode 100644
index 000000000..4ac83f7c7
--- /dev/null
+++ b/db/migrate/20220328133331_add_rent_value_check.rb
@@ -0,0 +1,5 @@
+class AddRentValueCheck < ActiveRecord::Migration[7.0]
+ def change
+ add_column :case_logs, :rent_value_check, :boolean
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1468b9dc9..966aa74be 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -231,6 +231,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.string "relat6"
t.string "relat7"
t.string "relat8"
+ t.boolean "rent_value_check"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
end
diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml
index e64b91d20..1e05d6dc7 100644
--- a/spec/fixtures/exports/case_logs.xml
+++ b/spec/fixtures/exports/case_logs.xml
@@ -173,5 +173,6 @@
+
diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb
new file mode 100644
index 000000000..461cfe561
--- /dev/null
+++ b/spec/models/validations/soft_validations_spec.rb
@@ -0,0 +1,73 @@
+require "rails_helper"
+
+RSpec.describe Validations::SoftValidations do
+ let(:record) { FactoryBot.create(:case_log) }
+
+ describe "rent min max validations" do
+ before do
+ LaRentRange.create!(
+ ranges_rent_id: "1",
+ la: "E07000223",
+ beds: 1,
+ lettype: 1,
+ soft_min: 12.41,
+ soft_max: 89.54,
+ hard_min: 9.87,
+ hard_max: 100.99,
+ start_year: 2021,
+ )
+
+ record.la = "E07000223"
+ record.lettype = 1
+ record.beds = 1
+ record.period = 1
+ record.startdate = Time.zone.local(2021, 10, 10)
+ end
+
+ context "when validating soft min" do
+ before do
+ record.brent = 11
+ end
+
+ it "returns out of soft min range if no startdate is given" do
+ record.startdate = nil
+ expect(record)
+ .not_to be_rent_in_soft_min_range
+ end
+
+ it "returns out of soft min range if no brent is given" do
+ record.brent = nil
+ expect(record)
+ .not_to be_rent_in_soft_min_range
+ end
+
+ it "returns true if weekly rent is in soft min range" do
+ expect(record)
+ .to be_rent_in_soft_min_range
+ end
+ end
+
+ context "when validating soft max" do
+ before do
+ record.brent = 90
+ end
+
+ it "returns out of soft max range if no startdate is given" do
+ record.startdate = nil
+ expect(record)
+ .not_to be_rent_in_soft_max_range
+ end
+
+ it "returns out of soft max range if no brent is given" do
+ record.brent = nil
+ expect(record)
+ .not_to be_rent_in_soft_max_range
+ end
+
+ it "returns true if weekly rent is in soft max range" do
+ expect(record)
+ .to be_rent_in_soft_max_range
+ end
+ end
+ end
+end