Browse Source

feat: display label columns for la and prevloc, and show codes for previous la and prevloc fields

pull/847/head
natdeanlewissoftwire 2 years ago
parent
commit
234dd006b7
  1. 8
      app/models/case_log.rb
  2. 17
      app/services/csv/case_log_csv_service.rb

8
app/models/case_log.rb

@ -442,6 +442,14 @@ class CaseLog < ApplicationRecord
created_by&.is_dpo created_by&.is_dpo
end end
def la_label
la
end
def prevloc_label
prevloc
end
def self.to_csv(user = nil) def self.to_csv(user = nil)
Csv::CaseLogCsvService.new(user).to_csv Csv::CaseLogCsvService.new(user).to_csv
end end

17
app/services/csv/case_log_csv_service.rb

@ -1,6 +1,6 @@
module Csv module Csv
class CaseLogCsvService class CaseLogCsvService
CSV_FIELDS_TO_OMIT = %w[hhmemb net_income_value_check sale_or_letting first_time_property_let_as_social_housing renttype needstype postcode_known is_la_inferred totchild totelder totadult net_income_known is_carehome previous_la_known is_previous_la_inferred age1_known age2_known age3_known age4_known age5_known age6_known age7_known age8_known letting_allocation_unknown details_known_2 details_known_3 details_known_4 details_known_5 details_known_6 details_known_7 details_known_8 rent_type wrent wscharge wpschrge wsupchrg wtcharge wtshortfall rent_value_check old_form_id old_id retirement_value_check tshortfall_known pregnancy_value_check hhtype new_old vacdays].freeze CSV_FIELDS_TO_OMIT = %w[hhmemb net_income_value_check sale_or_letting first_time_property_let_as_social_housing renttype needstype postcode_known is_la_inferred totchild totelder totadult net_income_known is_carehome previous_la_known is_previous_la_inferred age1_known age2_known age3_known age4_known age5_known age6_known age7_known age8_known letting_allocation_unknown details_known_2 details_known_3 details_known_4 details_known_5 details_known_6 details_known_7 details_known_8 rent_type wrent wscharge wpschrge wsupchrg wtcharge wtshortfall rent_value_check old_form_id old_id retirement_value_check tshortfall_known pregnancy_value_check hhtype new_old vacdays la prevloc].freeze
def initialize(user) def initialize(user)
@user = user @user = user
@ -13,11 +13,17 @@ module Csv
CaseLog.all.find_each do |record| CaseLog.all.find_each do |record|
csv << @attributes.map do |att| csv << @attributes.map do |att|
if %w[la prevloc].include? att
label_from_value(record.send(att))
elsif %w[la_label prevloc_label].include? att
record.form.get_question(att.remove("_label"), record)&.label_from_value(record.send(att)) || label_from_value(record.send(att))
else
record.form.get_question(att, record)&.label_from_value(record.send(att)) || label_from_value(record.send(att)) record.form.get_question(att, record)&.label_from_value(record.send(att)) || label_from_value(record.send(att))
end end
end end
end end
end end
end
private private
@ -34,9 +40,10 @@ module Csv
scheme_attributes = %w[scheme_id location_id] scheme_attributes = %w[scheme_id location_id]
intersecting_attributes = ordered_form_questions & CaseLog.attribute_names - scheme_attributes intersecting_attributes = ordered_form_questions & CaseLog.attribute_names - scheme_attributes
remaining_attributes = CaseLog.attribute_names - intersecting_attributes - scheme_attributes remaining_attributes = CaseLog.attribute_names - intersecting_attributes - scheme_attributes
la_fields = %w[la_label prevloc_label]
@attributes = (metadata_fields + intersecting_attributes + remaining_attributes - metadata_id_fields + %w[unittype_sh] + scheme_attributes).uniq @attributes = (metadata_fields + intersecting_attributes + remaining_attributes - metadata_id_fields + %w[unittype_sh] + scheme_attributes + la_fields).uniq
move_is_inferred_fields move_la_fields
@attributes -= CSV_FIELDS_TO_OMIT if @user.present? && !@user.support? @attributes -= CSV_FIELDS_TO_OMIT if @user.present? && !@user.support?
end end
@ -59,8 +66,8 @@ module Csv
attributes attributes
end end
def move_is_inferred_fields def move_la_fields
{ la: "is_la_inferred", prevloc: "is_previous_la_inferred" }.each do |inferred_field, field| { la: "is_la_inferred", la: "la_label", prevloc: "is_previous_la_inferred", prevloc: "prevloc_label" }.each do |inferred_field, field|
@attributes.delete(field) @attributes.delete(field)
@attributes.insert(@attributes.find_index(inferred_field.to_s), field) @attributes.insert(@attributes.find_index(inferred_field.to_s), field)
end end

Loading…
Cancel
Save