diff --git a/lib/tasks/confirm_charges_soft_validations.rake b/lib/tasks/confirm_charges_soft_validations.rake index 5f2cc270d..061148bc1 100644 --- a/lib/tasks/confirm_charges_soft_validations.rake +++ b/lib/tasks/confirm_charges_soft_validations.rake @@ -1,6 +1,12 @@ desc "Confirms scharge, pscharge and supcharge soft validations for completed logs" task confirm_charges_soft_validations: :environment do - LettingsLog.where(status: "completed").each do |log| + LettingsLog.where(status: "completed").filter_by_year(2022).each do |log| + log.update!(scharge_value_check: 0, values_updated_at: Time.zone.now) if log.scharge_value_check.blank? && log.scharge_over_soft_max? + log.update!(pscharge_value_check: 0, values_updated_at: Time.zone.now) if log.pscharge_value_check.blank? && log.pscharge_over_soft_max? + log.update!(supcharg_value_check: 0, values_updated_at: Time.zone.now) if log.supcharg_value_check.blank? && log.supcharg_over_soft_max? + end + + LettingsLog.where(status: "completed").filter_by_year(2023).each do |log| log.update!(scharge_value_check: 0, values_updated_at: Time.zone.now) if log.scharge_value_check.blank? && log.scharge_over_soft_max? log.update!(pscharge_value_check: 0, values_updated_at: Time.zone.now) if log.pscharge_value_check.blank? && log.pscharge_over_soft_max? log.update!(supcharg_value_check: 0, values_updated_at: Time.zone.now) if log.supcharg_value_check.blank? && log.supcharg_over_soft_max? diff --git a/spec/lib/tasks/confirm_charges_soft_validations_spec.rb b/spec/lib/tasks/confirm_charges_soft_validations_spec.rb index d914b5f86..6e202e40b 100644 --- a/spec/lib/tasks/confirm_charges_soft_validations_spec.rb +++ b/spec/lib/tasks/confirm_charges_soft_validations_spec.rb @@ -53,6 +53,16 @@ RSpec.describe "confirm_charges_soft_validations" do expect(lettings_log.values_updated_at).to be_nil end + it "does not confirm scharge value check for 2021 logs" do + lettings_log.scharge = 404 + lettings_log.skip_update_status = true + lettings_log.startdate = Time.zone.local(2021, 4, 1) + lettings_log.save!(validate: false) + lettings_log.skip_update_status = nil + expect { task.invoke }.not_to change(lettings_log.reload, :scharge_value_check) + expect(lettings_log.values_updated_at).to be_nil + end + it "confirms pscharge value check for lettings logs with pscharge over soft max" do lettings_log.pscharge = 204 lettings_log.skip_update_status = true @@ -92,6 +102,16 @@ RSpec.describe "confirm_charges_soft_validations" do expect(lettings_log.values_updated_at).to be_nil end + it "does not confirm pscharge value check for 2021 logs" do + lettings_log.pscharge = 204 + lettings_log.skip_update_status = true + lettings_log.startdate = Time.zone.local(2021, 4, 1) + lettings_log.save!(validate: false) + lettings_log.skip_update_status = nil + expect { task.invoke }.not_to change(lettings_log.reload, :pscharge_value_check) + expect(lettings_log.values_updated_at).to be_nil + end + it "confirms supcharg value check for lettings logs with supcharg over soft max" do lettings_log.supcharg = 204 lettings_log.skip_update_status = true @@ -130,6 +150,16 @@ RSpec.describe "confirm_charges_soft_validations" do expect { task.invoke }.not_to change(lettings_log.reload, :supcharg_value_check) expect(lettings_log.values_updated_at).to be_nil end + + it "does not confirm supcharg value check for 2021 logs" do + lettings_log.supcharg = 204 + lettings_log.skip_update_status = true + lettings_log.startdate = Time.zone.local(2021, 4, 1) + lettings_log.save!(validate: false) + lettings_log.skip_update_status = nil + expect { task.invoke }.not_to change(lettings_log.reload, :supcharg_value_check) + expect(lettings_log.values_updated_at).to be_nil + end end end end