Browse Source

Clear location/scheme in remaining exportable logs

pull/2144/head
Kat 2 years ago
parent
commit
bc133a8bd0
  1. 12
      app/services/bulk_update_from_csv/update_locations_from_csv_service.rb
  2. 3
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

12
app/services/bulk_update_from_csv/update_locations_from_csv_service.rb

@ -111,14 +111,18 @@ private
location["scheme_id"] = 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_logs_with_startdate = LettingsLog.where(location_id: location.id).after_date(editable_from_date)
editable_logs_with_startdate.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_with_startdate.map(&:id).join(', ')}")
editable_logs = LettingsLog.where(location_id: location.id).after_date(editable_from_date)
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.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
remaining_logs_to_export = LettingsLog.where(location_id: location.id).after_date(exportable_from_date)
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
else
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with scheme_code: #{value}. Scheme with id #{value} is not in the database")

3
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -423,15 +423,16 @@ RSpec.describe "bulk_update" do
lettings_log_5.startdate = Time.zone.local(2021, 4, 1)
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("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("Cleared 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("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 location_code: E09000033")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with type_of_unit: Bungalow")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with units: 10")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with mobility_type: Wheelchair-user standard")
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("Cannot update location #{locations[0].id} with status as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Cannot update location #{locations[0].id} with active_dates as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Saved location #{locations[0].id}.")

Loading…
Cancel
Save