diff --git a/app/models/case_log.rb b/app/models/case_log.rb
index f45c592e7..2bc3335d2 100644
--- a/app/models/case_log.rb
+++ b/app/models/case_log.rb
@@ -185,7 +185,7 @@ class CaseLog < ApplicationRecord
end
def has_first_let_vacancy_reason?
- [11, 12, 13].include?(rsnvac)
+ [15, 16, 17].include?(rsnvac)
end
def previous_tenancy_was_temporary?
@@ -351,6 +351,9 @@ private
self.vmonth = property_void_date.month
self.vyear = property_void_date.year
end
+ if rsnvac.present?
+ self.newprop = has_first_let_vacancy_reason? ? 1 : 2
+ end
self.incref = 1 if net_income_refused?
self.other_hhmemb = hhmemb - 1 if hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type]
diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb
index abb7ee05e..0341cc365 100644
--- a/app/models/validations/date_validations.rb
+++ b/app/models/validations/date_validations.rb
@@ -60,6 +60,6 @@ private
end
def is_rsnvac_first_let?(record)
- [11, 12, 13].include?(record["rsnvac"])
+ [15, 16, 17].include?(record["rsnvac"])
end
end
diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json
index 7c79550e1..3f3fdf31f 100644
--- a/config/forms/2021_2022.json
+++ b/config/forms/2021_2022.json
@@ -710,14 +710,14 @@
"hint_text": "",
"type": "radio",
"answer_options": {
- "12": {
+ "15": {
+ "value": "First let of new-build property"
+ },
+ "16": {
"value": "First let of conversion, rehabilitation or acquired property"
},
- "13": {
+ "17": {
"value": "First let of leased property"
- },
- "11": {
- "value": "First let of new-build property"
}
}
}
@@ -886,11 +886,11 @@
"depends_on": [
{
"renewal": 0,
- "rsnvac": 12
+ "rsnvac": 16
},
{
"renewal": 0,
- "rsnvac": 13
+ "rsnvac": 17
}
]
},
@@ -908,7 +908,7 @@
"depends_on": [
{
"renewal": 0,
- "rsnvac": 11
+ "rsnvac": 15
}
]
},
@@ -945,11 +945,11 @@
"depends_on": [
{
"renewal": 0,
- "rsnvac": 12
+ "rsnvac": 16
},
{
"renewal": 0,
- "rsnvac": 13
+ "rsnvac": 17
}
]
}
diff --git a/db/migrate/20220325114252_add_newprop_derived_variable.rb b/db/migrate/20220325114252_add_newprop_derived_variable.rb
new file mode 100644
index 000000000..0e30498a0
--- /dev/null
+++ b/db/migrate/20220325114252_add_newprop_derived_variable.rb
@@ -0,0 +1,7 @@
+class AddNewpropDerivedVariable < ActiveRecord::Migration[7.0]
+ def change
+ change_table :case_logs, bulk: true do |t|
+ t.column :newprop, :integer
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 545cecd7d..a4488ce6e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -223,6 +223,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "vmonth"
t.integer "vyear"
t.decimal "wchchrg", precision: 10, scale: 2
+ t.integer "newprop"
t.string "relat2"
t.string "relat3"
t.string "relat4"
diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml
index 639768427..6f2148f0b 100644
--- a/spec/fixtures/exports/case_logs.xml
+++ b/spec/fixtures/exports/case_logs.xml
@@ -165,6 +165,7 @@
11
2019
+ 2
P
diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb
index 9684f80a0..ee8215211 100644
--- a/spec/models/case_log_spec.rb
+++ b/spec/models/case_log_spec.rb
@@ -1577,6 +1577,38 @@ RSpec.describe CaseLog do
end
end
end
+
+ context "when the data provider is filling in the reason for the property being vacant" do
+ let!(:first_let_case_log) do
+ described_class.create({
+ managing_organisation: organisation,
+ owning_organisation: organisation,
+ first_time_property_let_as_social_housing: 1,
+ })
+ end
+
+ let!(:relet_case_log) do
+ described_class.create({
+ managing_organisation: organisation,
+ owning_organisation: organisation,
+ first_time_property_let_as_social_housing: 0,
+ })
+ end
+
+ it "the newprop variable is correctly derived and saved as 1 for a first let vacancy reason" do
+ first_let_case_log.update!({ rsnvac: 15 })
+ record_from_db = ActiveRecord::Base.connection.execute("select newprop from case_logs where id=#{first_let_case_log.id}").to_a[0]
+ expect(record_from_db["newprop"]).to eq(1)
+ expect(first_let_case_log["newprop"]).to eq(1)
+ end
+
+ it "the newprop variable is correctly derived and saved as 2 for anything that is not a first let vacancy reason" do
+ relet_case_log.update!({ rsnvac: 2 })
+ record_from_db = ActiveRecord::Base.connection.execute("select newprop from case_logs where id=#{relet_case_log.id}").to_a[0]
+ expect(record_from_db["newprop"]).to eq(2)
+ expect(relet_case_log["newprop"]).to eq(2)
+ end
+ end
end
describe "resetting invalidated fields" do
diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb
index 877ff72fc..9ab24f747 100644
--- a/spec/models/validations/date_validations_spec.rb
+++ b/spec/models/validations/date_validations_spec.rb
@@ -65,7 +65,7 @@ RSpec.describe Validations::DateValidations do
context "when reason for vacancy is first let of property" do
it "validates that no major repair date is provided for a new build" do
- record.rsnvac = 11
+ record.rsnvac = 15
record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"])
@@ -73,7 +73,7 @@ RSpec.describe Validations::DateValidations do
end
it "validates that no major repair date is provided for a conversion" do
- record.rsnvac = 12
+ record.rsnvac = 16
record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"])
@@ -81,7 +81,7 @@ RSpec.describe Validations::DateValidations do
end
it "validates that no major repair date is provided for a leased property" do
- record.rsnvac = 13
+ record.rsnvac = 17
record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"])
diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb
index 4461cd24f..12d7b7206 100644
--- a/spec/models/validations/property_validations_spec.rb
+++ b/spec/models/validations/property_validations_spec.rb
@@ -235,13 +235,13 @@ RSpec.describe Validations::PropertyValidations do
it "expects to have a first let reason for vacancy" do
record.first_time_property_let_as_social_housing = 1
- record.rsnvac = 11
+ record.rsnvac = 15
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty
- record.rsnvac = 12
+ record.rsnvac = 16
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty
- record.rsnvac = 13
+ record.rsnvac = 17
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty
end
@@ -250,15 +250,15 @@ RSpec.describe Validations::PropertyValidations do
context "when the property has been let as social housing before" do
it "validates that the reason for vacancy is not a first let as social housing reason" do
record.first_time_property_let_as_social_housing = 0
- record.rsnvac = 11
+ record.rsnvac = 15
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"])
.to include(match I18n.t("validations.property.rsnvac.first_let_not_social"))
- record.rsnvac = 12
+ record.rsnvac = 16
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"])
.to include(match I18n.t("validations.property.rsnvac.first_let_not_social"))
- record.rsnvac = 13
+ record.rsnvac = 17
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"])
.to include(match I18n.t("validations.property.rsnvac.first_let_not_social"))
@@ -266,13 +266,13 @@ RSpec.describe Validations::PropertyValidations do
it "expects the reason for vacancy to be a first let as social housing reason" do
record.first_time_property_let_as_social_housing = 1
- record.rsnvac = 11
+ record.rsnvac = 15
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty
- record.rsnvac = 12
+ record.rsnvac = 16
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty
- record.rsnvac = 13
+ record.rsnvac = 17
property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty
end