diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 347973077..d8b726842 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -343,6 +343,11 @@ private self.month = startdate.month self.year = startdate.year end + if property_void_date.present? + self.vday = property_void_date.day + self.vmonth = property_void_date.month + self.vyear = property_void_date.year + end self.incref = 1 if net_income_refused? self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? self.renttype = RENT_TYPE_MAPPING[rent_type] diff --git a/db/migrate/20220321142903_add_void_date_day_month_year_fields.rb b/db/migrate/20220321142903_add_void_date_day_month_year_fields.rb new file mode 100644 index 000000000..5accbb1f9 --- /dev/null +++ b/db/migrate/20220321142903_add_void_date_day_month_year_fields.rb @@ -0,0 +1,9 @@ +class AddVoidDateDayMonthYearFields < ActiveRecord::Migration[7.0] + def change + change_table :case_logs, bulk: true do |t| + t.column :vday, :integer + t.column :vmonth, :integer + t.column :vyear, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 38fcc3d26..e28e022c4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -225,6 +225,9 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.decimal "wtcharge", precision: 10, scale: 2 t.decimal "wtshortfall", precision: 10, scale: 2 t.integer "housingneeds" + t.integer "vday" + t.integer "vmonth" + t.integer "vyear" 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/factories/case_log.rb b/spec/factories/case_log.rb index 4fffc22f0..f23f3c10c 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -63,6 +63,9 @@ FactoryBot.define do unittype_gn { 2 } beds { 3 } property_void_date { "03/11/2019" } + vday { 3 } + vmonth { 11 } + vyear { 2019 } offered { 2 } wchair { 1 } earnings { 68 } diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 14fcd404a..3b6ff4637 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -64,6 +64,9 @@ "property_building_type": "dummy", "beds": 3, "property_void_date": "10/10/2020", + "vday": 10, + "vmonth": 10, + "vyear": 2020, "majorrepairs": 1, "mrcdate": "11/11/2020", "mrcday": 11, diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index cbd70ecd6..73c9fb3ce 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -167,5 +167,8 @@ 162.5 6.0 1 + 3 + 11 + 2019 diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index e80e7216e..15d0ef132 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -200,6 +200,7 @@ RSpec.describe CaseLog do previous_postcode: "M2 2AE", startdate: Time.gm(2021, 10, 10), mrcdate: Time.gm(2021, 5, 4), + property_void_date: Time.gm(2021, 3, 3), net_income_known: 2, other_hhmemb: 6, rent_type: 4, @@ -231,6 +232,16 @@ RSpec.describe CaseLog do expect(record_from_db["mrcyear"]).to eq(2021) end + it "correctly derives and saves partial and full major property void date" do + record_from_db = ActiveRecord::Base.connection.execute("select vday, vmonth, vyear, property_void_date from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["property_void_date"].day).to eq(3) + expect(record_from_db["property_void_date"].month).to eq(3) + expect(record_from_db["property_void_date"].year).to eq(2021) + expect(record_from_db["vday"]).to eq(3) + expect(record_from_db["vmonth"]).to eq(3) + expect(record_from_db["vyear"]).to eq(2021) + end + it "correctly derives and saves incref" do record_from_db = ActiveRecord::Base.connection.execute("select incref from case_logs where id=#{case_log.id}").to_a[0] expect(record_from_db["incref"]).to eq(1)