Browse Source

Log updates before clearing locations and schemes

pull/2144/head
Kat 2 years ago
parent
commit
4df960e678
  1. 6
      app/services/bulk_update_from_csv/update_locations_from_csv_service.rb
  2. 4
      app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb
  3. 10
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

6
app/services/bulk_update_from_csv/update_locations_from_csv_service.rb

@ -112,17 +112,17 @@ private
Rails.logger.info("Updating location #{original_attributes['location_code']} with scheme: S#{scheme.id}") Rails.logger.info("Updating location #{original_attributes['location_code']} with scheme: S#{scheme.id}")
editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date
editable_logs = LettingsLog.where(location_id: location.id).after_date(editable_from_date) editable_logs = LettingsLog.where(location_id: location.id).after_date(editable_from_date)
Rails.logger.info("Clearing location and scheme for logs with startdate and location #{location.id}. Log IDs: #{editable_logs.map(&:id).join(', ')}")
editable_logs.update!(location: nil, scheme: nil, values_updated_at: Time.zone.now) editable_logs.update!(location: nil, scheme: nil, values_updated_at: Time.zone.now)
Rails.logger.info("Cleared location and scheme for logs with startdate and location #{location.id}. Log IDs: #{editable_logs.map(&:id).join(', ')}")
logs_without_start_date = LettingsLog.where(scheme_id: scheme.id).where(startdate: nil) logs_without_start_date = LettingsLog.where(scheme_id: scheme.id).where(startdate: nil)
Rails.logger.info("Clearing location and scheme for logs without startdate and location #{location.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}")
logs_without_start_date.update!(location: nil, scheme: nil, values_updated_at: Time.zone.now) logs_without_start_date.update!(location: nil, scheme: nil, values_updated_at: Time.zone.now)
Rails.logger.info("Cleared location and scheme for logs without startdate and location #{location.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}")
exportable_from_date = FormHandler.instance.previous_collection_start_date exportable_from_date = FormHandler.instance.previous_collection_start_date
remaining_logs_to_export = LettingsLog.where(location_id: location.id).after_date(exportable_from_date) remaining_logs_to_export = LettingsLog.where(location_id: location.id).after_date(exportable_from_date)
Rails.logger.info("Clearing location and scheme for non editable logs with location #{location.id}. Log IDs: #{remaining_logs_to_export.map(&:id).join(', ')}")
remaining_logs_to_export.update_all(location_id: nil, scheme_id: nil, values_updated_at: Time.zone.now) remaining_logs_to_export.update_all(location_id: nil, scheme_id: nil, values_updated_at: Time.zone.now)
Rails.logger.info("Cleared location and scheme for non editable logs with location #{location.id}. Log IDs: #{remaining_logs_to_export.map(&:id).join(', ')}")
end end
else else
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with scheme_code: #{value}. Scheme with id #{value} is not in the database") Rails.logger.info("Cannot update location #{original_attributes['location_code']} with scheme_code: #{value}. Scheme with id #{value} is not in the database")

4
app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb

@ -95,12 +95,12 @@ private
editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date editable_from_date = FormHandler.instance.earliest_open_for_editing_collection_start_date
editable_logs_with_startdate = LettingsLog.where(scheme_id: scheme.id).after_date(editable_from_date) editable_logs_with_startdate = LettingsLog.where(scheme_id: scheme.id).after_date(editable_from_date)
Rails.logger.info("Clearing location and scheme for logs with startdate and scheme S#{scheme.id}. Log IDs: #{editable_logs_with_startdate.map(&:id).join(', ')}")
editable_logs_with_startdate.update!(location: nil, scheme: nil) editable_logs_with_startdate.update!(location: nil, scheme: nil)
Rails.logger.info("Cleared location and scheme for logs with startdate and scheme S#{scheme.id}. Log IDs: #{editable_logs_with_startdate.map(&:id).join(', ')}")
logs_without_start_date = LettingsLog.where(scheme_id: scheme.id).where(startdate: nil) logs_without_start_date = LettingsLog.where(scheme_id: scheme.id).where(startdate: nil)
Rails.logger.info("Clearing location and scheme for logs without startdate and scheme S#{scheme.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}")
logs_without_start_date.update!(location: nil, scheme: nil) logs_without_start_date.update!(location: nil, scheme: nil)
Rails.logger.info("Cleared location and scheme for logs without startdate and scheme S#{scheme.id}. Log IDs: #{logs_without_start_date.map(&:id).join(', ')}")
end end
else else
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with owning_organisation: #{value}. Organisation with name #{value} is not in the database or is not related to current organisation") Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with owning_organisation: #{value}. Organisation with name #{value} is not in the database or is not related to current organisation")

10
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -204,8 +204,8 @@ RSpec.describe "bulk_update" do
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with service_name: Updated test name") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with service_name: Updated test name")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with sensitive: No") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with sensitive: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with scheme_type: Direct Access Hostel") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with scheme_type: Direct Access Hostel")
expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs with startdate and scheme S#{schemes[0].id}. Log IDs: ") expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs with startdate and scheme S#{schemes[0].id}. Log IDs: ")
expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs without startdate and scheme S#{schemes[0].id}. Log IDs: #{lettings_log.id}, #{lettings_log_4.id}, #{lettings_log_5.id}") expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs without startdate and scheme S#{schemes[0].id}. Log IDs: #{lettings_log.id}, #{lettings_log_4.id}, #{lettings_log_5.id}")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with arrangement_type: Another registered stock owner") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with arrangement_type: Another registered stock owner")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with primary_client_group: People with drug problems") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with primary_client_group: People with drug problems")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with has_other_client_group: No") expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with has_other_client_group: No")
@ -424,9 +424,9 @@ RSpec.describe "bulk_update" do
lettings_log_5.save!(validate: false) lettings_log_5.save!(validate: false)
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with scheme: S#{different_scheme.id}") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with scheme: S#{different_scheme.id}")
expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs with startdate and location #{locations[0].id}. Log IDs: #{lettings_log.id}") expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs with startdate and location #{locations[0].id}. Log IDs: #{lettings_log.id}")
expect(Rails.logger).to receive(:info).with("Cleared location and scheme for logs without startdate and location #{locations[0].id}. Log IDs: ") expect(Rails.logger).to receive(:info).with("Clearing location and scheme for logs without startdate and location #{locations[0].id}. Log IDs: ")
expect(Rails.logger).to receive(:info).with("Cleared location and scheme for non editable logs with location #{locations[0].id}. Log IDs: ") expect(Rails.logger).to receive(:info).with("Clearing location and scheme for non editable logs with location #{locations[0].id}. Log IDs: #{lettings_log_4.id}")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with postcode: B11BB") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with postcode: B11BB")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with name: Updated name") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with name: Updated name")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with location_code: E09000033") expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with location_code: E09000033")

Loading…
Cancel
Save