From 234dd006b7540feeb6993704a9d5da837e1f74e0 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 25 Aug 2022 13:59:11 +0100 Subject: [PATCH] feat: display label columns for la and prevloc, and show codes for previous la and prevloc fields --- app/models/case_log.rb | 8 ++++++++ app/services/csv/case_log_csv_service.rb | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 3f61ed4e4..f5d9c94d1 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -442,6 +442,14 @@ class CaseLog < ApplicationRecord created_by&.is_dpo end + def la_label + la + end + + def prevloc_label + prevloc + end + def self.to_csv(user = nil) Csv::CaseLogCsvService.new(user).to_csv end diff --git a/app/services/csv/case_log_csv_service.rb b/app/services/csv/case_log_csv_service.rb index ff6474b80..c763e269f 100644 --- a/app/services/csv/case_log_csv_service.rb +++ b/app/services/csv/case_log_csv_service.rb @@ -1,6 +1,6 @@ module Csv 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) @user = user @@ -13,7 +13,13 @@ module Csv CaseLog.all.find_each do |record| csv << @attributes.map do |att| - record.form.get_question(att, record)&.label_from_value(record.send(att)) || label_from_value(record.send(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)) + end end end end @@ -34,9 +40,10 @@ module Csv scheme_attributes = %w[scheme_id location_id] intersecting_attributes = ordered_form_questions & CaseLog.attribute_names - 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 - move_is_inferred_fields + @attributes = (metadata_fields + intersecting_attributes + remaining_attributes - metadata_id_fields + %w[unittype_sh] + scheme_attributes + la_fields).uniq + move_la_fields @attributes -= CSV_FIELDS_TO_OMIT if @user.present? && !@user.support? end @@ -59,8 +66,8 @@ module Csv attributes end - def move_is_inferred_fields - { la: "is_la_inferred", prevloc: "is_previous_la_inferred" }.each do |inferred_field, field| + def move_la_fields + { la: "is_la_inferred", la: "la_label", prevloc: "is_previous_la_inferred", prevloc: "prevloc_label" }.each do |inferred_field, field| @attributes.delete(field) @attributes.insert(@attributes.find_index(inferred_field.to_s), field) end