Browse Source

Add issue type column

pull/1953/head
Kat 3 years ago
parent
commit
7d6a5871f2
  1. 64
      app/services/csv/missing_addresses_csv_service.rb
  2. 4
      spec/fixtures/files/missing_lettings_logs_addresses.csv
  3. 6
      spec/fixtures/files/missing_lettings_logs_addresses_and_town_or_city.csv
  4. 4
      spec/fixtures/files/missing_lettings_logs_town_or_city.csv
  5. 4
      spec/fixtures/files/missing_sales_logs_addresses.csv
  6. 6
      spec/fixtures/files/missing_sales_logs_addresses_and_town_or_city.csv
  7. 4
      spec/fixtures/files/missing_sales_logs_town_or_city.csv

64
app/services/csv/missing_addresses_csv_service.rb

@ -9,25 +9,29 @@ module Csv
logs_with_missing_town_or_city = @organisation.managed_lettings_logs.imported.filter_by_year(2023).where(needstype: 1, town_or_city: nil, uprn_known: [0, nil]).where.not(old_form_id: nil).where.not(address_line1: nil)
return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty?
generate_missing_lettings_addresses_csv(logs_with_missing_addresses + logs_with_missing_town_or_city)
end
def create_missing_sales_addresses_csv
logs_with_missing_addresses = @organisation.sales_logs.imported.filter_by_year(2023).where(address_line1: nil, town_or_city: nil, uprn_known: [0, nil]).where.not(old_form_id: nil)
logs_with_missing_town_or_city = @organisation.sales_logs.imported.filter_by_year(2023).where(town_or_city: nil, uprn_known: [0, nil]).where.not(old_form_id: nil).where.not(address_line1: nil)
return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty?
CSV.generate(headers: true) do |csv|
csv << ["Issue type", "Lettings log ID", "Tenancy start date", "Tenant code", "Property code", "Log owner", "Owning organisation name", "Managing organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
generate_missing_sales_addresses_csv(logs_with_missing_addresses + logs_with_missing_town_or_city)
logs_with_missing_addresses.each do |log|
csv << ["Full address required",
log.id,
log.startdate&.to_date,
log.tenancycode,
log.propcode,
log.created_by&.email,
log.owning_organisation&.name,
log.managing_organisation&.name,
log.address_line1,
log.address_line2,
log.town_or_city,
log.county,
log.postcode_full,
log.la]
end
private
def generate_missing_lettings_addresses_csv(logs)
CSV.generate(headers: true) do |csv|
csv << ["Lettings log ID", "Tenancy start date", "Tenant code", "Property code", "Log owner", "Owning organisation name", "Managing organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
logs.each do |log|
csv << [log.id,
logs_with_missing_town_or_city.each do |log|
csv << ["Missing town or city",
log.id,
log.startdate&.to_date,
log.tenancycode,
log.propcode,
@ -44,12 +48,32 @@ module Csv
end
end
def generate_missing_sales_addresses_csv(logs)
def create_missing_sales_addresses_csv
logs_with_missing_addresses = @organisation.sales_logs.imported.filter_by_year(2023).where(address_line1: nil, town_or_city: nil, uprn_known: [0, nil]).where.not(old_form_id: nil)
logs_with_missing_town_or_city = @organisation.sales_logs.imported.filter_by_year(2023).where(town_or_city: nil, uprn_known: [0, nil]).where.not(old_form_id: nil).where.not(address_line1: nil)
return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty?
CSV.generate(headers: true) do |csv|
csv << ["Sales log ID", "Sale completion date", "Purchaser code", "Log owner", "Owning organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
csv << ["Issue type", "Sales log ID", "Sale completion date", "Purchaser code", "Log owner", "Owning organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
logs_with_missing_addresses.each do |log|
csv << ["Full address required",
log.id,
log.saledate&.to_date,
log.purchid,
log.created_by&.email,
log.owning_organisation&.name,
log.address_line1,
log.address_line2,
log.town_or_city,
log.county,
log.postcode_full,
log.la]
end
logs.each do |log|
csv << [log.id,
logs_with_missing_town_or_city.each do |log|
csv << ["Missing town or city",
log.id,
log.saledate&.to_date,
log.purchid,
log.created_by&.email,

4
spec/fixtures/files/missing_lettings_logs_addresses.csv vendored

@ -1,2 +1,2 @@
Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,,,,,,
Issue type,Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
Full address required,{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,,,,,,

1 Issue type Lettings log ID Tenancy start date Tenant code Property code Log owner Owning organisation name Managing organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 Full address required {id} 2023-04-05 tenancycode propcode testy@example.com Address test Address test

6
spec/fixtures/files/missing_lettings_logs_addresses_and_town_or_city.csv vendored

@ -1,3 +1,3 @@
Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,,,,,,
{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,existing address,,,,,
Issue type,Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
Full address required,{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,,,,,,
Missing town or city,{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,existing address,,,,,

1 Issue type Lettings log ID Tenancy start date Tenant code Property code Log owner Owning organisation name Managing organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 Full address required {id} 2023-04-05 tenancycode propcode testy@example.com Address test Address test
3 Missing town or city {id} 2023-04-05 tenancycode propcode testy@example.com Address test Address test existing address

4
spec/fixtures/files/missing_lettings_logs_town_or_city.csv vendored

@ -1,2 +1,2 @@
Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,existing address,,,,,
Issue type,Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
Missing town or city,{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,existing address,,,,,

1 Issue type Lettings log ID Tenancy start date Tenant code Property code Log owner Owning organisation name Managing organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 Missing town or city {id} 2023-04-05 tenancycode propcode testy@example.com Address test Address test existing address

4
spec/fixtures/files/missing_sales_logs_addresses.csv vendored

@ -1,2 +1,2 @@
Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,purchaser code,testy@example.com,Address test,,,,,,
Issue type,Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
Full address required,{id},2023-04-05,purchaser code,testy@example.com,Address test,,,,,,

1 Issue type Sales log ID Sale completion date Purchaser code Log owner Owning organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 Full address required {id} 2023-04-05 purchaser code testy@example.com Address test

6
spec/fixtures/files/missing_sales_logs_addresses_and_town_or_city.csv vendored

@ -1,3 +1,3 @@
Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,purchaser code,testy@example.com,Address test,,,,,,
{id},2023-04-05,purchaser code,testy@example.com,Address test,existing address line 1,,,,,
Issue type,Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
Full address required,{id},2023-04-05,purchaser code,testy@example.com,Address test,,,,,,
Missing town or city,{id},2023-04-05,purchaser code,testy@example.com,Address test,existing address line 1,,,,,

1 Issue type Sales log ID Sale completion date Purchaser code Log owner Owning organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 Full address required {id} 2023-04-05 purchaser code testy@example.com Address test
3 Missing town or city {id} 2023-04-05 purchaser code testy@example.com Address test existing address line 1

4
spec/fixtures/files/missing_sales_logs_town_or_city.csv vendored

@ -1,2 +1,2 @@
Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,purchaser code,testy@example.com,Address test,existing address line 1,,,,,
Issue type,Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
Missing town or city,{id},2023-04-05,purchaser code,testy@example.com,Address test,existing address line 1,,,,,

1 Issue type Sales log ID Sale completion date Purchaser code Log owner Owning organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 Missing town or city {id} 2023-04-05 purchaser code testy@example.com Address test existing address line 1
Loading…
Cancel
Save