| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -2,7 +2,12 @@ namespace :bulk_update do | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  desc "Update logs with specific criteria and set manual_address_entry_selected to true" | 
					 | 
					 | 
					 | 
					  desc "Update logs with specific criteria and set manual_address_entry_selected to true" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  task update_manual_address_entry_selected: :environment do | 
					 | 
					 | 
					 | 
					  task update_manual_address_entry_selected: :environment do | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    updated_lettings_logs_count = 0 | 
					 | 
					 | 
					 | 
					    updated_lettings_logs_count = 0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    lettings_status_changed_log_ids = [] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    lettings_postcode_fixed_count = 0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    updated_sales_logs_count = 0 | 
					 | 
					 | 
					 | 
					    updated_sales_logs_count = 0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    sales_status_changed_log_ids = [] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    sales_postcode_fixed_count = 0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    lettings_logs = LettingsLog.filter_by_year(2024) | 
					 | 
					 | 
					 | 
					    lettings_logs = LettingsLog.filter_by_year(2024) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                               .where(status: %w[in_progress completed]) | 
					 | 
					 | 
					 | 
					                               .where(status: %w[in_progress completed]) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                               .where(needstype: 1, manual_address_entry_selected: false, uprn: nil) | 
					 | 
					 | 
					 | 
					                               .where(needstype: 1, manual_address_entry_selected: false, uprn: nil) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -17,12 +22,23 @@ namespace :bulk_update do | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Rails.logger.info "Could not save changes to lettings log #{log.id}" | 
					 | 
					 | 
					 | 
					        Rails.logger.info "Could not save changes to lettings log #{log.id}" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end | 
					 | 
					 | 
					 | 
					      end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      status_post_change = log.status | 
					 | 
					 | 
					 | 
					      status_post_change = log.status | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      unless status_pre_change == status_post_change | 
					 | 
					 | 
					 | 
					      if status_pre_change != status_post_change | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Rails.logger.info "Status changed from #{status_pre_change} to #{status_post_change} for lettings log #{log.id}" | 
					 | 
					 | 
					 | 
					        if log.postcode_full.nil? && log.address_line1 == log.address_line1_input | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          log.postcode_full = log.postcode_full_input | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          log.save! | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if log.status == status_pre_change | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          lettings_postcode_fixed_count += 1 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        else | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          Rails.logger.info "Status changed from #{status_pre_change} to #{status_post_change} for lettings log #{log.id}" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          lettings_status_changed_log_ids << log.id | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end | 
					 | 
					 | 
					 | 
					      end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    end | 
					 | 
					 | 
					 | 
					    end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    puts "#{updated_lettings_logs_count} lettings logs updated." | 
					 | 
					 | 
					 | 
					    puts "#{updated_lettings_logs_count} lettings logs updated." | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    puts "Lettings logs with status changes: [#{lettings_status_changed_log_ids.join(', ')}]" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    puts "Lettings logs where postcode fix maintained status: #{lettings_postcode_fixed_count}" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    sales_logs = SalesLog.filter_by_year(2024) | 
					 | 
					 | 
					 | 
					    sales_logs = SalesLog.filter_by_year(2024) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                         .where(status: %w[in_progress completed]) | 
					 | 
					 | 
					 | 
					                         .where(status: %w[in_progress completed]) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -38,11 +54,22 @@ namespace :bulk_update do | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Rails.logger.info "Could not save changes to sales log #{log.id}" | 
					 | 
					 | 
					 | 
					        Rails.logger.info "Could not save changes to sales log #{log.id}" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end | 
					 | 
					 | 
					 | 
					      end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      status_post_change = log.status | 
					 | 
					 | 
					 | 
					      status_post_change = log.status | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      unless status_pre_change == status_post_change | 
					 | 
					 | 
					 | 
					      if status_pre_change != status_post_change | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Rails.logger.info "Status changed from #{status_pre_change} to #{status_post_change} for sales log #{log.id}" | 
					 | 
					 | 
					 | 
					        if log.postcode_full.nil? && log.address_line1 == log.address_line1_input | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          log.postcode_full = log.postcode_full_input | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          log.save! | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if log.status == status_pre_change | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          sales_postcode_fixed_count += 1 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        else | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          Rails.logger.info "Status changed from #{status_pre_change} to #{status_post_change} for sales log #{log.id}" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          sales_status_changed_log_ids << log.id | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end | 
					 | 
					 | 
					 | 
					      end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    end | 
					 | 
					 | 
					 | 
					    end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    puts "#{updated_sales_logs_count} sales logs updated." | 
					 | 
					 | 
					 | 
					    puts "#{updated_sales_logs_count} sales logs updated." | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    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 | 
					 | 
					 | 
					 | 
					  end | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					end | 
					 | 
					 | 
					 | 
					end | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					 | 
					
  |