Browse Source

Log updated records (#2245)

pull/2248/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
79ced8f7a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      lib/tasks/clear_invalidated_earnings.rake
  2. 3
      spec/lib/tasks/clear_invalidated_earnings_spec.rb

1
lib/tasks/clear_invalidated_earnings.rake

@ -3,6 +3,7 @@ task clear_invalidated_earnings: :environment do
LettingsLog.filter_by_year(2023).find_each do |lettings_log| LettingsLog.filter_by_year(2023).find_each do |lettings_log|
lettings_log.validate_net_income(lettings_log) lettings_log.validate_net_income(lettings_log)
if lettings_log.errors[:earnings].present? if lettings_log.errors[:earnings].present?
Rails.logger.info "Clearing earnings for lettings log #{lettings_log.id}, owning_organisation_id: #{lettings_log.owning_organisation_id}, managing_organisation_id: #{lettings_log.managing_organisation_id}, startdate: #{lettings_log.startdate.to_date}, tenancy reference: #{lettings_log.tenancycode}, property reference: #{lettings_log.propcode}, created_by: #{lettings_log.created_by.email}(#{lettings_log.created_by_id})"
lettings_log.earnings = nil lettings_log.earnings = nil
lettings_log.incfreq = nil lettings_log.incfreq = nil
lettings_log.save!(validate: false) lettings_log.save!(validate: false)

3
spec/lib/tasks/clear_invalidated_earnings_spec.rb

@ -15,7 +15,7 @@ RSpec.describe "clear_invalidated_earnings" do
context "when the rake task is run" do context "when the rake task is run" do
context "and there are 2023 logs with invalid earnings" do context "and there are 2023 logs with invalid earnings" do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil) } let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil, tenancycode: "123", propcode: "321") }
before do before do
lettings_log.startdate = Time.zone.local(2023, 4, 4) lettings_log.startdate = Time.zone.local(2023, 4, 4)
@ -32,6 +32,7 @@ RSpec.describe "clear_invalidated_earnings" do
expect(lettings_log.earnings).to eq(20) expect(lettings_log.earnings).to eq(20)
expect(lettings_log.hhmemb).to eq(1) expect(lettings_log.hhmemb).to eq(1)
expect(lettings_log.ecstat1).to eq(1) expect(lettings_log.ecstat1).to eq(1)
expect(Rails.logger).to receive(:info).with("Clearing earnings for lettings log #{lettings_log.id}, owning_organisation_id: #{lettings_log.owning_organisation_id}, managing_organisation_id: #{lettings_log.managing_organisation_id}, startdate: 2023-04-04, tenancy reference: 123, property reference: 321, created_by: #{user.email}(#{user.id})")
task.invoke task.invoke
lettings_log.reload lettings_log.reload

Loading…
Cancel
Save