Browse Source

Remove user_type attribute and update some definitions

pull/2539/head
Manny Dinssa 2 years ago
parent
commit
329d808a96
  1. 2
      app/models/csv_variable_definition.rb
  2. 8
      app/models/user.rb
  3. 9
      app/services/csv/lettings_log_csv_service.rb
  4. 9
      app/services/csv/sales_log_csv_service.rb
  5. 4
      app/services/imports/variable_definitions_service.rb
  6. 2
      config/csv/definitions/lettings_support_download_23_24.csv
  7. 2
      config/csv/definitions/lettings_support_download_24_25.csv
  8. 2
      config/csv/definitions/lettings_user_download_23_24.csv
  9. 2
      config/csv/definitions/lettings_user_download_24_25.csv
  10. 2
      config/csv/definitions/sales_support_download_23_24.csv
  11. 2
      config/csv/definitions/sales_support_download_24_25.csv
  12. 2
      config/csv/definitions/sales_user_download_23_24.csv
  13. 2
      config/csv/definitions/sales_user_download_24_25.csv
  14. 5
      db/migrate/20240813142947_remove_user_type_from_csv_variable_definitions.rb
  15. 24
      db/schema.rb
  16. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv
  17. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv
  18. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv
  19. 2
      spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv
  20. 2
      spec/fixtures/files/sales_logs_csv_export_codes_23.csv
  21. 2
      spec/fixtures/files/sales_logs_csv_export_codes_24.csv
  22. 2
      spec/fixtures/files/sales_logs_csv_export_labels_23.csv
  23. 2
      spec/fixtures/files/sales_logs_csv_export_labels_24.csv
  24. 2
      spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv
  25. 2
      spec/fixtures/variable_definitions/lettings_support_download_24_25.csv
  26. 2
      spec/fixtures/variable_definitions/lettings_user_download_23_24.csv
  27. 2
      spec/fixtures/variable_definitions/lettings_user_download_24_25.csv
  28. 2
      spec/fixtures/variable_definitions/sales_support_download_23_24.csv
  29. 2
      spec/fixtures/variable_definitions/sales_support_download_24_25.csv
  30. 2
      spec/fixtures/variable_definitions/sales_user_download_23_24.csv
  31. 2
      spec/fixtures/variable_definitions/sales_user_download_24_25.csv

2
app/models/csv_variable_definition.rb

@ -2,11 +2,9 @@ class CsvVariableDefinition < ApplicationRecord
validates :variable, presence: true
validates :definition, presence: true
validates :log_type, presence: true, inclusion: { in: %w[lettings sales] }
validates :user_type, presence: true, inclusion: { in: %w[user support] }
validates :year, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 2000, less_than_or_equal_to: 2099 }
attribute :last_accessed, :datetime
scope :user, -> { where(user_type: "user") }
scope :lettings, -> { where(log_type: "lettings") }
scope :sales, -> { where(log_type: "sales") }
end

8
app/models/user.rb

@ -110,14 +110,6 @@ class User < ApplicationRecord
SalesLog.filter_by_managing_organisation(organisation.absorbed_organisations + [organisation])
end
def variable_definitions
if support?
CsvVariableDefinition.all
else
CsvVariableDefinition.user
end
end
def schemes
if support?
Scheme.all

9
app/services/csv/lettings_log_csv_service.rb

@ -266,16 +266,11 @@ module Csv
end
def lettings_log_definitions
definitions = @user.variable_definitions.lettings
definitions.group_by { |record| [record.variable, record.definition] }
CsvVariableDefinition.lettings.group_by { |record| [record.variable, record.definition] }
.map do |_, options|
exact_match = options.find { |definition| definition.year == @year && definition.user_type == @user.user_type }
exact_match = options.find { |definition| definition.year == @year }
next exact_match if exact_match
recent_match = options.select { |definition| definition.user_type == @user.user_type }.max_by(&:year)
next recent_match if recent_match
options.max_by(&:year)
end
end

9
app/services/csv/sales_log_csv_service.rb

@ -170,16 +170,11 @@ module Csv
end
def sales_log_definitions
definitions = @user.variable_definitions.sales
definitions.group_by { |record| [record.variable, record.definition] }
CsvVariableDefinition.sales.group_by { |record| [record.variable, record.definition] }
.map do |_, options|
exact_match = options.find { |definition| definition.year == @year && definition.user_type == @user.user_type }
exact_match = options.find { |definition| definition.year == @year }
next exact_match if exact_match
recent_match = options.select { |definition| definition.user_type == @user.user_type }.max_by(&:year)
next recent_match if recent_match
options.max_by(&:year)
end
end

4
app/services/imports/variable_definitions_service.rb

@ -22,7 +22,6 @@ module Imports
file_name = File.basename(file, ".csv")
parsed_file_name = file_name.split("_")
log_type = parsed_file_name[0]
user_type = parsed_file_name[1]
year = "20#{parsed_file_name[3]}".to_i
records_added = 0
@ -41,12 +40,9 @@ module Imports
variable: variable.strip,
definition: definition.strip,
log_type:,
user_type:,
year:,
)
records_added += 1
elsif existing_record.user_type == "support" && user_type == "user"
existing_record.update!(user_type: "user")
end
end

2
config/csv/definitions/lettings_support_download_23_24.csv

@ -56,7 +56,7 @@ tenancy,What is the type of tenancy?
tenancyother,If 'Other', what is the type of tenancy?
tenancylength,What is the length of the fixed-term tenancy to the nearest year?
sheltered,Is this letting in sheltered accommodation?
declaration,Has the tenant seen the DLUHC privacy notice?
declaration,Has the tenant seen the MHCLG privacy notice?
hhmemb,How many people live in the household at this letting?
pregnancy_value_check,The following soft validation was confirmed: You told us somebody in the household is pregnant. You also told us there are no female tenants living at the property.
refused,Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8

Can't render this file because it has a wrong number of fields in line 20.

2
config/csv/definitions/lettings_support_download_24_25.csv

@ -63,7 +63,7 @@ tenancy,What is the type of tenancy?
tenancyother,If 'Other', what is the type of tenancy?
tenancylength,What is the length of the fixed-term tenancy to the nearest year?
sheltered,Is this letting in sheltered accommodation?
declaration,Has the tenant seen the DLUHC privacy notice?
declaration,Has the tenant seen the MHCLG privacy notice?
hhmemb,How many people live in the household at this letting?
pregnancy_value_check,The following soft validation was confirmed: You told us somebody in the household is pregnant. You also told us there are no female tenants living at the property.
refused,Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8

Can't render this file because it has a wrong number of fields in line 25.

2
config/csv/definitions/lettings_user_download_23_24.csv

@ -48,7 +48,7 @@ tenancy,What is the type of tenancy?
tenancyother,If 'Other', what is the type of tenancy?
tenancylength,What is the length of the fixed-term tenancy to the nearest year?
sheltered,Is this letting in sheltered accommodation?
declaration,Has the tenant seen the DLUHC privacy notice?
declaration,Has the tenant seen the MHCLG privacy notice?
hhmemb,How many people live in the household at this letting?
refused,Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8
age1,What is the lead tenant's age?

Can't render this file because it has a wrong number of fields in line 17.

2
config/csv/definitions/lettings_user_download_24_25.csv

@ -48,7 +48,7 @@ tenancy,What is the type of tenancy?
tenancyother,If 'Other', what is the type of tenancy?
tenancylength,What is the length of the fixed-term tenancy to the nearest year?
sheltered,Is this letting in sheltered accommodation?
declaration,Has the tenant seen the DLUHC privacy notice?
declaration,Has the tenant seen the MHCLG privacy notice?
hhmemb,How many people live in the household at this letting?
refused,Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8
age1,What is the lead tenant's age?

Can't render this file because it has a wrong number of fields in line 18.

2
config/csv/definitions/sales_support_download_23_24.csv

@ -37,7 +37,7 @@ LA,LA code
LANAME,LA name
WCHAIR,Is the property built or adapted to wheelchair-user standards?
NOINT,Did you interview the buyer to answer these questions?
PRIVACYNOTICE,Has the buyer seen the DLUHC privacy notice?
PRIVACYNOTICE,Has the buyer seen the MHCLG privacy notice?
AGE1,What is buyer 1's age?
SEX1,Which of these best describes buyer 1's gender identity?
ETHNICGROUP1,What is buyer 1's ethnic group?

Can't render this file because it has a wrong number of fields in line 20.

2
config/csv/definitions/sales_support_download_24_25.csv

@ -23,7 +23,7 @@ LIVEINBUYER,Will the buyer(s) live in the property?
JOINT,Is this a joint purchase?
JOINTMORE,Are there more than 2 joint buyers of this property?
NOINT,Did you interview the buyer to answer these questions?
PRIVACYNOTICE,Has the buyer seen the DLUHC privacy notice?
PRIVACYNOTICE,Has the buyer seen the MHCLG privacy notice?
UPRN,What is the UPRN of the property?
ADDRESS1,Address line 1
ADDRESS2,Address line 2

Can't render this file because it has a wrong number of fields in line 20.

2
config/csv/definitions/sales_user_download_23_24.csv

@ -36,7 +36,7 @@ la,LA code
la_label,LA name
wchair,Is the property built or adapted to wheelchair-user standards?
noint,Did you interview the buyer to answer these questions?
privacynotice,Has the buyer seen the DLUHC privacy notice?
privacynotice,Has the buyer seen the MHCLG privacy notice?
age1,What is buyer 1's age?
sex1,Which of these best describes buyer 1's gender identity?
ethnic_group,What is buyer 1's ethnic group?

Can't render this file because it has a wrong number of fields in line 19.

2
config/csv/definitions/sales_user_download_24_25.csv

@ -39,7 +39,7 @@ la,LA code
la_label,LA name
wchair,Is the property built or adapted to wheelchair-user standards?
noint,Did you interview the buyer to answer these questions?
privacynotice,Has the buyer seen the DLUHC privacy notice?
privacynotice,Has the buyer seen the MHCLG privacy notice?
age1,What is buyer 1's age?
sex1,Which of these best describes buyer 1's gender identity?
ethnic_group,What is buyer 1's ethnic group?

Can't render this file because it has a wrong number of fields in line 19.

5
db/migrate/20240813142947_remove_user_type_from_csv_variable_definitions.rb

@ -0,0 +1,5 @@
class RemoveUserTypeFromCsvVariableDefinitions < ActiveRecord::Migration[7.0]
def change
remove_column :csv_variable_definitions, :user_type, :string
end
end

24
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_07_26_152326) do
ActiveRecord::Schema[7.0].define(version: 2024_08_13_142947) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -50,13 +50,11 @@ ActiveRecord::Schema[7.0].define(version: 2024_07_26_152326) do
t.string "variable", null: false
t.string "definition", null: false
t.string "log_type", null: false
t.string "user_type", null: false
t.integer "year", null: false
t.datetime "last_accessed"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.check_constraint "log_type::text = ANY (ARRAY['lettings'::character varying, 'sales'::character varying]::text[])", name: "log_type_check"
t.check_constraint "user_type::text = ANY (ARRAY['user'::character varying, 'support'::character varying]::text[])", name: "user_type_check"
t.check_constraint "year >= 2000 AND year <= 2099", name: "year_check"
end
@ -431,19 +429,21 @@ ActiveRecord::Schema[7.0].define(version: 2024_07_26_152326) do
create_table "merge_requests", force: :cascade do |t|
t.integer "requesting_organisation_id"
t.text "other_merging_organisations"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "status"
t.integer "absorbing_organisation_id"
t.boolean "new_absorbing_organisation"
t.boolean "telephone_number_correct"
t.string "new_telephone_number"
t.string "new_organisation_name"
t.string "new_organisation_address_line1"
t.string "new_organisation_address_line2"
t.string "new_organisation_postcode"
t.string "new_organisation_telephone_number"
t.datetime "merge_date"
t.integer "requester_id"
t.string "helpdesk_ticket"
t.integer "total_users"
t.integer "total_schemes"
t.integer "total_lettings_logs"
t.integer "total_sales_logs"
t.integer "total_stock_owners"
t.integer "total_managing_agents"
t.boolean "signed_dsa", default: false
t.datetime "discarded_at"
end
create_table "notifications", force: :cascade do |t|

2
spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/sales_logs_csv_export_codes_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/sales_logs_csv_export_codes_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/sales_logs_csv_export_labels_23.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/sales_logs_csv_export_labels_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/files/sales_logs_csv_export_non_support_labels_24.csv vendored

File diff suppressed because one or more lines are too long

2
spec/fixtures/variable_definitions/lettings_support_download_24_25.csv vendored

@ -201,7 +201,7 @@ wtshortfall,Weekly total rent shortfall charge for tenant receiving housing bene
scheme_code,What scheme does this letting belong to?
scheme_service_name,From scheme code, we map to the scheme name
scheme_confidential,Does the scheme contain confidential information?
SCHTYPE,What is this type of scheme? (Direct access hostel, Foyer, Housing for older people or Other supported housing
SCHTYPE,What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing
scheme_registered_under_care_act,Is this scheme registered under the Care Standards Act 2000?
scheme_owning_organisation_name,Which organisation owns the housing stock for this scheme?
scheme_primary_client_group,What client group is this scheme intended for?

Can't render this file because it has a wrong number of fields in line 25.

2
spec/fixtures/variable_definitions/lettings_user_download_23_24.csv vendored

@ -151,7 +151,7 @@ tshortfall,Estimated outstanding amount
scheme_code,What scheme does this letting belong to?
scheme_service_name,From scheme code, we map to the scheme name
scheme_confidential,Does the scheme contain confidential information?
SCHTYPE,What is this type of scheme? (Direct access hostel, Foyer, Housing for older people or Other supported housing
SCHTYPE,What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing
scheme_registered_under_care_act,Is this scheme registered under the Care Standards Act 2000?
scheme_owning_organisation_name,Which organisation owns the housing stock for this scheme?
scheme_primary_client_group,What client group is this scheme intended for?

Can't render this file because it has a wrong number of fields in line 17.

2
spec/fixtures/variable_definitions/lettings_user_download_24_25.csv vendored

@ -152,7 +152,7 @@ tshortfall,Estimated outstanding amount
scheme_code,What scheme does this letting belong to?
scheme_service_name,From scheme code, we map to the scheme name
scheme_confidential,Does the scheme contain confidential information?
SCHTYPE,What is this type of scheme? (Direct access hostel, Foyer, Housing for older people or Other supported housing
SCHTYPE,What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing
scheme_registered_under_care_act,Is this scheme registered under the Care Standards Act 2000?
scheme_owning_organisation_name,Which organisation owns the housing stock for this scheme?
scheme_primary_client_group,What client group is this scheme intended for?

Can't render this file because it has a wrong number of fields in line 18.

2
spec/fixtures/variable_definitions/sales_support_download_23_24.csv vendored

@ -81,7 +81,7 @@ PREGYRHA,Was the buyer registered with their PRP (HA)?
PREGOTHER,Was the buyer registered with another PRP (HA)?
PREGLA,Was the buyer registered with the local authority?
PREGGHB,Was the buyer registered with a Help to Buy agent?
PREGBLANK,None of the above four options apply
PREGBLANK,Populated if pregyrha, pregother, pregla and pregghb are blank
BUY2LIVING,At the time of purchase, was buyer 2 living at the same address as buyer 1?
PREVTEN2,What was buyer 2's previous tenure?
HHREGRES,Have any of the buyers ever served as a regular in the UK armed forces?

Can't render this file because it has a wrong number of fields in line 20.

2
spec/fixtures/variable_definitions/sales_support_download_24_25.csv vendored

@ -90,7 +90,7 @@ PREGYRHA,Was the buyer registered with their PRP (HA)?
PREGOTHER,Was the buyer registered with another PRP (HA)?
PREGLA,Was the buyer registered with the local authority?
PREGGHB,Was the buyer registered with a Help to Buy agent?
PREGBLANK,None of the above four options apply
PREGBLANK,Populated if pregyrha, pregother, pregla and pregghb are blank
BUY2LIVING,At the time of purchase, was buyer 2 living at the same address as buyer 1?
PREVTEN2,What was buyer 2's previous tenure?
HHREGRES,Have any of the buyers ever served as a regular in the UK armed forces?

Can't render this file because it has a wrong number of fields in line 20.

2
spec/fixtures/variable_definitions/sales_user_download_23_24.csv vendored

@ -24,7 +24,7 @@ jointmore,Are there more than 2 joint buyers of this property?
beds,How many bedrooms does the property have?
proptype,What type of unit is the property?
builtype,Which type of building is the property?
uprn,Property's UPRN
uprn,What is the UPRN of the property?
uprn_confirmed,We found an address that might be this property. Is this the property address?
address_line1,Address line 1
address_line2,Address line 2

Can't render this file because it has a wrong number of fields in line 19.

2
spec/fixtures/variable_definitions/sales_user_download_24_25.csv vendored

@ -24,7 +24,7 @@ jointmore,Are there more than 2 joint buyers of this property?
beds,How many bedrooms does the property have?
proptype,What type of unit is the property?
builtype,Which type of building is the property?
uprn,Property's UPRN
uprn,What is the UPRN of the property?
uprn_confirmed,We found an address that might be this property. Is this the property address?
address_line1_input,Address line 1 input from address matching feature
postcode_full_input,Postcode input from address matching feature

Can't render this file because it has a wrong number of fields in line 19.
Loading…
Cancel
Save