From 4daca6567bbee34f8c0c6ea0d60221d07de0f77f Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 3 May 2023 15:57:08 +0100 Subject: [PATCH] bulk upload sales 2023 handles arbitrary ordering --- .../bulk_upload/sales/year2023/row_parser.rb | 2 + spec/factories/sales_log.rb | 3 ++ spec/support/bulk_upload/sales_log_to_csv.rb | 41 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 8e3baec8f..41e50a112 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -156,6 +156,8 @@ class BulkUpload::Sales::Year2023::RowParser attribute :bulk_upload attribute :block_log_creation, :boolean, default: -> { false } + attribute :field_blank + attribute :field_1, :string attribute :field_2, :string attribute :field_3, :integer diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index b17efec90..0ea3787dc 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -126,5 +126,8 @@ FactoryBot.define do mortgagelender { 5 } extrabor { 1 } end + trait :with_uprn do + uprn { rand(999_999_999_999).to_s } + end end end diff --git a/spec/support/bulk_upload/sales_log_to_csv.rb b/spec/support/bulk_upload/sales_log_to_csv.rb index 650eaad65..c15adcda6 100644 --- a/spec/support/bulk_upload/sales_log_to_csv.rb +++ b/spec/support/bulk_upload/sales_log_to_csv.rb @@ -16,6 +16,15 @@ class BulkUpload::SalesLogToCsv (row_prefix + to_2022_row).flatten.join(",") + line_ending end + def to_2023_csv_row(seed: nil) + if seed + row = to_2023_row.shuffle(random: Random.new(seed)) + (row_prefix + row).flatten.join(",") + line_ending + else + (row_prefix + to_2023_row).flatten.join(",") + line_ending + end + end + def default_2022_field_numbers (1..125).to_a end @@ -28,6 +37,34 @@ class BulkUpload::SalesLogToCsv end.flatten.join(",") + line_ending end + def default_2023_field_numbers_row(seed: nil) + if seed + ["Bulk upload field number"] + default_2023_field_numbers.shuffle(random: Random.new(seed)) + else + ["Bulk upload field number"] + default_2023_field_numbers + end.flatten.join(",") + line_ending + end + + def to_2023_row + to_2022_row + [ + log.uprn, + log.address_line1, + log.address_line2, + log.town_or_city, + log.county, + nil, # mistake and now field is left blank + log.ethnic_group2, + log.nationalbuy2, + nil, + log.buy2living, + log.prevtenbuy2, + log.hhregresstill, + log.prevshared, + log.staircasesale, + log.soctenant, + ] + end + def to_2022_row [ log.purchid, # 1 @@ -177,6 +214,10 @@ class BulkUpload::SalesLogToCsv private + def default_2023_field_numbers + [6, 3, 4, 5, nil, 28, 30, 38, 47, 51, 55, 59, 31, 39, 48, 52, 56, 60, 37, 46, 50, 54, 58, 35, 43, 49, 53, 57, 61, 32, 33, 78, 80, 79, 81, 83, 84, nil, 62, 66, 64, 65, 63, 67, 69, 70, 68, 76, 77, 16, 17, 18, 26, 24, 25, 27, 8, 91, 95, 96, 97, 92, 93, 94, 98, 100, 101, 103, 104, 106, 110, 111, 112, 113, 114, 9, 116, 117, 118, 120, 124, 125, 126, 10, 11, nil, 127, 129, 133, 134, 135, 1, 2, nil, 73, nil, 75, 107, 108, 121, 122, 130, 131, 82, 109, 123, 132, 115, 15, 86, 87, 29, 7, 12, 13, 14, 36, 44, 45, 88, 89, 102, 105, 119, 128, 19, 20, 21, 22, 23, 34, 40, 41, 42, 71, 72, 74, 85, 90, 99] + end + def hhregres if log.hhregres == 1 log.hhregresstill