Browse Source

feat: add bulk upload address info to sales csv download

pull/2324/head
natdeanlewissoftwire 2 years ago
parent
commit
ac7f21237a
  1. 2
      app/jobs/email_csv_job.rb
  2. 6
      app/services/bulk_upload/sales/year2024/row_parser.rb
  3. 8
      app/services/csv/sales_log_csv_service.rb
  4. 10
      db/migrate/20240319115447_add_entered_address_fields_to_sales_logs.rb
  5. 8
      db/schema.rb
  6. 4
      spec/jobs/email_csv_job_spec.rb

2
app/jobs/email_csv_job.rb

@ -15,7 +15,7 @@ class EmailCsvJob < ApplicationJob
when "sales"
unfiltered_logs = organisation.present? && user.support? ? SalesLog.visible.where(owning_organisation_id: organisation.id) : user.sales_logs.visible
filtered_logs = FilterManager.filter_logs(unfiltered_logs, search_term, filters, all_orgs, user)
csv_string = Csv::SalesLogCsvService.new(export_type:).prepare_csv(filtered_logs)
csv_string = Csv::SalesLogCsvService.new(user:, export_type:).prepare_csv(filtered_logs)
end
filename = "#{[log_type, 'logs', organisation&.name, Time.zone.now].compact.join('-')}.csv"

6
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -863,9 +863,11 @@ private
attributes["builtype"] = field_21
attributes["la_known"] = field_29.present? ? 1 : 0
attributes["la"] = field_29
attributes["la_as_entered"] = field_29
attributes["is_la_inferred"] = false
attributes["pcodenk"] = 0 if postcode_full.present?
attributes["postcode_full"] = postcode_full
attributes["postcode_full_as_entered"] = postcode_full
attributes["wchair"] = field_30
attributes["type"] = sale_type
@ -931,9 +933,13 @@ private
attributes["uprn_confirmed"] = 1 if field_22.present?
attributes["skip_update_uprn_confirmed"] = true
attributes["address_line1"] = field_23
attributes["address_line1_as_entered"] = field_23
attributes["address_line2"] = field_24
attributes["address_line2_as_entered"] = field_24
attributes["town_or_city"] = field_25
attributes["town_or_city_as_entered"] = field_25
attributes["county"] = field_26
attributes["county_as_entered"] = field_26
attributes["address_line1_input"] = address_line1_input
attributes["postcode_full_input"] = postcode_full
attributes["select_best_address_match"] = true if field_22.blank?

8
app/services/csv/sales_log_csv_service.rb

@ -1,6 +1,7 @@
module Csv
class SalesLogCsvService
def initialize(export_type:)
def initialize(user:, export_type:)
@user = user
@export_type = export_type
@attributes = sales_log_attributes
end
@ -132,6 +133,8 @@ module Csv
"managing_organisation_id" => %w[managing_organisation_name],
}.freeze
def SUPPORT_ONLY_ATTRIBITES = %w[address_line1_as_entered address_line2_as_entered town_or_city_as_entered county_as_entered postcode_full_as_entered la_as_entered]
def sales_log_attributes
ordered_questions = FormHandler.instance.ordered_sales_questions_for_all_years
ordered_questions.reject! { |q| q.id.match?(/((?<!la)_known)|(_check)|(_asked)|nationality_all_group|nationality_all_buyer2_group/) }
@ -145,7 +148,8 @@ module Csv
end
end
non_question_fields = %w[id status duplicate_set_id created_at updated_at old_form_id collection_start_year creation_method is_dpo]
non_question_fields + attributes
final_attributes = non_question_fields + attributes
@user.support? ? final_attributes : final_attributes - SUPPORT_ONLY_ATTRIBUTES
end
def person_details_not_known?(log, attribute)

10
db/migrate/20240319115447_add_entered_address_fields_to_sales_logs.rb

@ -0,0 +1,10 @@
class AddEnteredAddressFieldsToSalesLogs < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :address_line1_as_entered, :string
add_column :sales_logs, :address_line2_as_entered, :string
add_column :sales_logs, :town_or_city_as_entered, :string
add_column :sales_logs, :county_as_entered, :string
add_column :sales_logs, :postcode_full_as_entered, :string
add_column :sales_logs, :la_as_entered, :string
end
end

8
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_03_19_092425) do
ActiveRecord::Schema[7.0].define(version: 2024_03_19_115447) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -675,6 +675,12 @@ ActiveRecord::Schema[7.0].define(version: 2024_03_19_092425) do
t.string "postcode_full_input"
t.integer "address_search_value_check"
t.string "uprn_selection"
t.string "address_line1_as_entered"
t.string "address_line2_as_entered"
t.string "town_or_city_as_entered"
t.string "county_as_entered"
t.string "postcode_full_as_entered"
t.string "la_as_entered"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"

4
spec/jobs/email_csv_job_spec.rb

@ -90,10 +90,10 @@ describe EmailCsvJob do
end
it "creates a SalesLogCsvService with the correct export type" do
expect(Csv::SalesLogCsvService).to receive(:new).with(export_type: "labels")
expect(Csv::SalesLogCsvService).to receive(:new).with(user:, export_type: "labels")
codes_only = false
job.perform(user, nil, {}, nil, nil, codes_only, "sales")
expect(Csv::SalesLogCsvService).to receive(:new).with(export_type: "codes")
expect(Csv::SalesLogCsvService).to receive(:new).with(user:, export_type: "codes")
codes_only = true
job.perform(user, nil, {}, nil, nil, codes_only, "sales")
end

Loading…
Cancel
Save