|
|
@ -47,22 +47,25 @@ class TestDataController < ApplicationController |
|
|
|
redirect_to sales_log_path(log) |
|
|
|
redirect_to sales_log_path(log) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def create_2024_test_sales_bulk_upload |
|
|
|
[2024, 2025].each do |year| |
|
|
|
return render_not_found unless FeatureToggle.create_test_logs_enabled? |
|
|
|
define_method("create_#{year}_test_sales_bulk_upload") do |
|
|
|
|
|
|
|
return render_not_found unless FeatureToggle.create_test_logs_enabled? |
|
|
|
file = Tempfile.new("test_sales_log.csv") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000) |
|
|
|
file = Tempfile.new("#{year}_test_sales_log.csv") |
|
|
|
log_to_csv = BulkUpload::SalesLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" }) |
|
|
|
# saledate { Time.zone.today } |
|
|
|
file.write(log_to_csv.default_field_numbers_row) |
|
|
|
log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000, county: "Somerset", saledate: Time.zone.local(year.to_i, rand(4..12), rand(1..28))) |
|
|
|
file.write(log_to_csv.to_csv_row) |
|
|
|
log_to_csv = BulkUpload::SalesLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" }) |
|
|
|
file.rewind |
|
|
|
file.write(log_to_csv.default_field_numbers_row) |
|
|
|
send_file file.path, type: "text/csv", |
|
|
|
file.write(log_to_csv.to_csv_row) |
|
|
|
filename: "test_sales_log.csv", |
|
|
|
file.rewind |
|
|
|
disposition: "attachment", |
|
|
|
send_file file.path, type: "text/csv", |
|
|
|
after_send: lambda { |
|
|
|
filename: "#{year}_test_sales_log.csv", |
|
|
|
file.close |
|
|
|
disposition: "attachment", |
|
|
|
file.unlink |
|
|
|
after_send: lambda { |
|
|
|
} |
|
|
|
file.close |
|
|
|
|
|
|
|
file.unlink |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|