|
|
|
@ -72,4 +72,48 @@ namespace :bulk_update do
|
|
|
|
|
puts "Sales logs with status changes: [#{sales_status_changed_log_ids.join(', ')}]" |
|
|
|
|
puts "Sales logs where postcode fix maintained status: #{sales_postcode_fixed_count}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
desc "Find logs to fix and update postcode_full if conditions are met" |
|
|
|
|
task update_postcode_full_preexisting_manual_entry_logs: :environment do |
|
|
|
|
updated_count = 0 |
|
|
|
|
fixed_count = 0 |
|
|
|
|
not_updated_count = 0 |
|
|
|
|
not_updated_ids = [] |
|
|
|
|
updated_but_not_fixed_ids = [] |
|
|
|
|
|
|
|
|
|
logs_to_fix = LettingsLog.filter_by_year(2024) |
|
|
|
|
.where(manual_address_entry_selected: true, uprn: nil, status: "in_progress", postcode_full: nil) |
|
|
|
|
.where(updated_at: Time.zone.parse("2025-03-19 16:00:00")..Time.zone.parse("2025-03-19 17:00:00")) |
|
|
|
|
|
|
|
|
|
logs_to_fix.find_each do |log| |
|
|
|
|
previous_version = log.versions[-2] |
|
|
|
|
previous_status = previous_version&.reify&.status |
|
|
|
|
|
|
|
|
|
if log.address_line1 == log.address_line1_input |
|
|
|
|
log.postcode_full = log.postcode_full_input |
|
|
|
|
if log.save |
|
|
|
|
Rails.logger.info "Updated postcode_full for lettings log #{log.id}" |
|
|
|
|
updated_count += 1 |
|
|
|
|
if log.status == previous_status |
|
|
|
|
fixed_count += 1 |
|
|
|
|
else |
|
|
|
|
updated_but_not_fixed_ids << log.id |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
Rails.logger.info "Could not save changes to lettings log #{log.id}" |
|
|
|
|
not_updated_count += 1 |
|
|
|
|
not_updated_ids << log.id |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
not_updated_count += 1 |
|
|
|
|
not_updated_ids << log.id |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
puts "#{updated_count} logs updated." |
|
|
|
|
puts "#{fixed_count} logs fixed." |
|
|
|
|
puts "#{not_updated_count} logs not updated." |
|
|
|
|
puts "IDs of logs not updated: [#{not_updated_ids.join(', ')}]" |
|
|
|
|
puts "IDs of logs updated but not fixed: [#{updated_but_not_fixed_ids.join(', ')}]" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|