Browse Source
# Conflicts: # spec/fixtures/files/lettings_log_csv_export_labels_24.csv # spec/fixtures/files/lettings_log_csv_export_labels_25.csvpull/3302/head
74 changed files with 771 additions and 775 deletions
@ -1 +1,5 @@
|
||||
You have given us the details for 0 of the <%= log.hholdcount %> other people in the household |
||||
<% if log.form.start_year_2026_or_later? %> |
||||
You have given us the details for 1 of the <%= log.hholdcount %> people in the household |
||||
<% else %> |
||||
You have given us the details for 0 of the <%= log.hholdcount %> other people in the household |
||||
<% end %> |
||||
|
||||
@ -1 +1,5 @@
|
||||
You have given us the details for <%= log.joint_purchase? ? 0 : 1 %> of the <%= log.hholdcount %> other people in the household |
||||
<% if log.form.start_year_2026_or_later? %> |
||||
You have given us the details for 2 of the <%= log.hholdcount %> people in the household |
||||
<% else %> |
||||
You have given us the details for <%= log.joint_purchase? ? 0 : 1 %> of the <%= log.hholdcount %> other people in the household |
||||
<% end %> |
||||
|
||||
@ -1 +1,5 @@
|
||||
You have given us the details for <%= log.joint_purchase? ? 1 : 2 %> of the <%= log.hholdcount %> other people in the household |
||||
<% if log.form.start_year_2026_or_later? %> |
||||
You have given us the details for 3 of the <%= log.hholdcount %> people in the household |
||||
<% else %> |
||||
You have given us the details for <%= log.joint_purchase? ? 1 : 2 %> of the <%= log.hholdcount %> other people in the household |
||||
<% end %> |
||||
|
||||
@ -1 +1,5 @@
|
||||
You have given us the details for <%= log.joint_purchase? ? 2 : 3 %> of the <%= log.hholdcount %> other people in the household |
||||
<% if log.form.start_year_2026_or_later? %> |
||||
You have given us the details for 4 of the <%= log.hholdcount %> people in the household |
||||
<% else %> |
||||
You have given us the details for <%= log.joint_purchase? ? 2 : 3 %> of the <%= log.hholdcount %> other people in the household |
||||
<% end %> |
||||
|
||||
@ -1 +1,5 @@
|
||||
You have given us the details for <%= log.joint_purchase? ? 3 : 4 %> of the <%= log.hholdcount %> other people in the household |
||||
<% if log.form.start_year_2026_or_later? %> |
||||
You have given us the details for 5 of the <%= log.hholdcount %> people in the household |
||||
<% else %> |
||||
You have given us the details for <%= log.joint_purchase? ? 3 : 4 %> of the <%= log.hholdcount %> other people in the household |
||||
<% end %> |
||||
|
||||
@ -0,0 +1,34 @@
|
||||
desc "Deletes all logs in a given collection year and earlier. Note that this operation is PERMANENT and this will bypass callbacks/paper trail. Use only as instructed in a yearly cleanup task." |
||||
task :delete_logs_in_collection_year_and_earlier, %i[year] => :environment do |_task, args| |
||||
year = args[:year].to_i |
||||
|
||||
if year < 2020 |
||||
raise ArgumentError, "Year must be above 2020. Make sure you've written out the entire year" |
||||
end |
||||
|
||||
if year > Time.zone.now.year - 3 |
||||
raise ArgumentError, "Year cannot be the last 3 years, as these may contain visible logs" |
||||
end |
||||
|
||||
puts "Deleting Logs before #{year}" |
||||
|
||||
puts "Deleting Sales Logs in batches of 10000" |
||||
logs = SalesLog.filter_by_year_or_earlier(year) |
||||
|
||||
logs.in_batches(of: 10_000).each_with_index do |logs, i| |
||||
puts "Deleting batch #{i + 1}" |
||||
logs.delete_all |
||||
end |
||||
puts "Done deleting Sales Logs" |
||||
|
||||
puts "Deleting Lettings Logs in batches of 10000" |
||||
logs = LettingsLog.filter_by_year_or_earlier(year) |
||||
|
||||
logs.in_batches(of: 10_000).each_with_index do |logs, i| |
||||
puts "Deleting batch #{i + 1}" |
||||
logs.delete_all |
||||
end |
||||
puts "Done deleting Lettings Logs" |
||||
|
||||
puts "Done deleting Logs before #{year}" |
||||
end |
||||
@ -0,0 +1,129 @@
|
||||
namespace :log_la_fix do |
||||
desc "For all logs missing an LA that could have one, call the postcode changed method to request a new one from postcodes API. For logs where an LA still cannot be found, this will set them back to in progress." |
||||
task :search_for_la_on_logs_with_nil_la, [:year] => :environment do |_task, args| |
||||
include CollectionTimeHelper |
||||
|
||||
year = args[:year]&.to_i || current_collection_start_year |
||||
|
||||
lettings_logs = LettingsLog.filter_by_year(year).where(la: nil, needstype: 1, status: "completed") |
||||
sales_logs = SalesLog.filter_by_year(year).where(la: nil, status: "completed") |
||||
lettings_logs_count = lettings_logs.count |
||||
sales_logs_count = sales_logs.count |
||||
|
||||
puts "Checking LA on #{lettings_logs_count} lettings logs in #{year}" |
||||
|
||||
i = 0 |
||||
lettings_logs.find_each do |log| |
||||
next unless log.valid? |
||||
|
||||
log.process_postcode_changes! |
||||
unless log.save |
||||
puts "Failed to save lettings log #{log.id}" |
||||
puts "Errors: #{log.errors.full_messages}" |
||||
end |
||||
|
||||
if log.la.nil? && log.status == "in_progress" |
||||
puts "#lettings##{log.id},\"#{log.tenancycode}\",\"#{log.propcode}\",#{log.owning_organisation_id},\"#{log.owning_organisation&.name}\",#{log.managing_organisation_id},\"#{log.managing_organisation&.name}\",#{log.assigned_to_id},\"#{log.assigned_to&.name}\",#{log.startdate},\"#{log.address_line1}\",\"#{log.address_line2}\",\"#{log.town_or_city}\",\"#{log.county}\",\"#{log.postcode_full}\",\"\",\"\"" |
||||
end |
||||
|
||||
i += 1 |
||||
if (i % 100).zero? |
||||
puts "Processed #{i} lettings logs" |
||||
end |
||||
end |
||||
|
||||
puts "Done #{lettings_logs_count} lettings logs" |
||||
|
||||
puts "Checking LA on #{sales_logs_count} sales logs in #{year}" |
||||
|
||||
i = 0 |
||||
sales_logs.find_each do |log| |
||||
next unless log.valid? |
||||
|
||||
log.process_postcode_changes! |
||||
unless log.save |
||||
puts "Failed to save sales log #{log.id}" |
||||
puts "Errors: #{log.errors.full_messages}" |
||||
end |
||||
|
||||
if log.la.nil? && log.status == "in_progress" |
||||
puts "#sales##{log.id},\"#{log.purchid}\",#{log.owning_organisation_id},\"#{log.owning_organisation&.name}\",#{log.managing_organisation_id},\"#{log.managing_organisation&.name}\",#{log.assigned_to_id},\"#{log.assigned_to&.name}\",#{log.saledate},\"#{log.address_line1}\",\"#{log.address_line2}\",\"#{log.town_or_city}\",\"#{log.county}\",\"#{log.postcode_full}\",\"\",\"\"" |
||||
end |
||||
|
||||
i += 1 |
||||
if (i % 100).zero? |
||||
puts "Processed #{i} sales logs" |
||||
end |
||||
end |
||||
|
||||
puts "Done #{sales_logs_count} sales logs" |
||||
|
||||
puts "Done" |
||||
end |
||||
|
||||
desc "Parse the output of search_for_la_on_logs_with_nil_la into separate lettings and sales CSV files" |
||||
task parse_logs_moved_to_incomplete_with_no_la: :environment do |
||||
require "csv" |
||||
|
||||
file = "output.txt" |
||||
|
||||
lettings_headers = %w[id tenancycode propcode owning_organisation_id owning_organisation managing_organisation_id managing_organisation assigned_to_id assigned_to startdate address_line1 address_line2 town_or_city county postcode_full la_ecode la_name] |
||||
sales_headers = %w[id purchid owning_organisation_id owning_organisation managing_organisation_id managing_organisation assigned_to_id assigned_to saledate address_line1 address_line2 town_or_city county postcode_full la_ecode la_name] |
||||
|
||||
lettings_csv = CSV.open("lettings_logs_moved_to_incomplete_with_no_la.csv", "w") |
||||
sales_csv = CSV.open("sales_logs_moved_to_incomplete_with_no_la.csv", "w") |
||||
|
||||
lettings_csv << lettings_headers |
||||
sales_csv << sales_headers |
||||
|
||||
File.readlines(file).each do |line| |
||||
line = line.strip |
||||
if line.start_with?("#lettings#") |
||||
row = CSV.parse_line(line.delete_prefix("#lettings#"), liberal_parsing: true) |
||||
lettings_csv << row |
||||
elsif line.start_with?("#sales#") |
||||
row = CSV.parse_line(line.delete_prefix("#sales#"), liberal_parsing: true) |
||||
sales_csv << row |
||||
end |
||||
end |
||||
|
||||
lettings_csv.close |
||||
sales_csv.close |
||||
|
||||
puts "Written lettings_logs_moved_to_incomplete_with_no_la.csv" |
||||
puts "Written sales_logs_moved_to_incomplete_with_no_la.csv" |
||||
end |
||||
|
||||
desc "Split lettings and sales CSVs by managing organisation into separate files per org" |
||||
task split_logs_by_managing_org: :environment do |
||||
require "csv" |
||||
|
||||
%w[lettings sales].each do |log_type| |
||||
input_file = "#{log_type}_logs_moved_to_incomplete_with_no_la.csv" |
||||
|
||||
rows_by_org = Hash.new { |h, k| h[k] = [] } |
||||
table = CSV.read(input_file, headers: true) |
||||
|
||||
table.each do |row| |
||||
org_name = row["managing_organisation"] |
||||
rows_by_org[org_name] << row |
||||
end |
||||
|
||||
rows_by_org.each do |org_name, rows| |
||||
if rows.size < 30 |
||||
puts "Skipping #{org_name} (#{rows.size} rows)" |
||||
next |
||||
end |
||||
|
||||
FileUtils.mkdir_p("log_output") |
||||
sanitised_name = org_name.parameterize(separator: "_") |
||||
output_file = "log_output/#{sanitised_name}_#{log_type}_logs_moved_to_incomplete_with_no_la.csv" |
||||
CSV.open(output_file, "w") do |csv| |
||||
csv << table.headers |
||||
rows.each { |row| csv << row } |
||||
end |
||||
puts "Written #{output_file} (#{rows.size} rows)" |
||||
end |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,24 @@
|
||||
desc "Remaps hhregresstill values for manually created 2025/26 sales logs" |
||||
task :remap_2025_hhregresstill_values, %i[before_datetime] => :environment do |_task, args| |
||||
usage_message = "Usage: rake remap_2025_hhregresstill_values['before_datetime']. before_datetime must be in format YYYY-MM-DDTHH:MM:SS" |
||||
raise usage_message if args[:before_datetime].blank? |
||||
|
||||
before_datetime = Time.zone.parse(args[:before_datetime]) |
||||
raise usage_message if before_datetime.nil? |
||||
|
||||
logs = SalesLog.filter_by_year(2025).where(bulk_upload_id: nil).where(hhregresstill: [5, 6, 7]).where("created_at < ?", before_datetime) |
||||
puts "Updating #{logs.count} sales logs" |
||||
|
||||
updated_ids = [] |
||||
logs.find_each do |log| |
||||
new_value = case log.hhregresstill |
||||
when 5 then 10 |
||||
when 6, 7 then 9 |
||||
end |
||||
log.update!(hhregresstill: new_value) |
||||
updated_ids << log.id |
||||
end |
||||
|
||||
puts "Updated log IDs: #{updated_ids.join(', ')}" |
||||
puts "Done" |
||||
end |
||||
@ -0,0 +1,11 @@
|
||||
desc "Rounds purchase price (the 'value' field) for sales logs in the database if not a whole number" |
||||
task round_value_for_2026_sales_logs: :environment do |
||||
logs = SalesLog.filter_by_year(2026).where("value % 1 != 0") |
||||
puts "Correcting #{logs.count} sales logs, #{logs.map(&:id)}" |
||||
|
||||
logs.find_each do |log| |
||||
log.update(value: log.value.round) |
||||
end |
||||
|
||||
puts "Done" |
||||
end |
||||
@ -0,0 +1,10 @@
|
||||
desc "For logs that fail the validate_housing_universal_credit_matches_income_proportion check created before we released it, clear the answer to the question" |
||||
task update_logs_with_invalid_hb_benefits_2026: :environment do |
||||
impacted_logs = LettingsLog.filter_by_year(2026).where(hb: [1, 6], benefits: 3) |
||||
|
||||
puts "#{impacted_logs.count} logs will be updated #{impacted_logs.map(&:id)}" |
||||
|
||||
impacted_logs.update!(benefits: nil, hb: nil) |
||||
|
||||
puts "Done" |
||||
end |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue