diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 472b82ed1..86f3231d1 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -426,7 +426,9 @@ class LettingsLog < Log end delegate :service_name, :sensitive, :registered_under_care_act, :primary_client_group, :has_other_client_group, :secondary_client_group, :owning_organisation, :managing_organisation, :support_type, :intended_stay, :created_at, prefix: "scheme", to: :scheme, allow_nil: true + delegate :service_name_before_type_cast, :sensitive_before_type_cast, :registered_under_care_act_before_type_cast, :primary_client_group_before_type_cast, :has_other_client_group_before_type_cast, :secondary_client_group_before_type_cast, :owning_organisation_before_type_cast, :managing_organisation_before_type_cast, :support_type_before_type_cast, :intended_stay_before_type_cast, :created_at_before_type_cast, prefix: "scheme", to: :scheme, allow_nil: true delegate :scheme_type, to: :scheme, allow_nil: true + delegate :scheme_type_before_type_cast, to: :scheme, allow_nil: true def scheme_code scheme&.id ? "S#{scheme.id}" : nil @@ -437,7 +439,9 @@ class LettingsLog < Log end delegate :postcode, :name, :units, :type_of_unit, :mobility_type, :startdate, prefix: "location", to: :location, allow_nil: true + delegate :postcode_before_type_cast, :name_before_type_cast, :units_before_type_cast, :type_of_unit_before_type_cast, :mobility_type_before_type_cast, :startdate_before_type_cast, prefix: "location", to: :location, allow_nil: true delegate :location_admin_district, to: :location, allow_nil: true + delegate :location_admin_district_before_type_cast, to: :location, allow_nil: true # This is not the location_code in the db, location.id is just called code in the UI def location_code @@ -495,6 +499,10 @@ class LettingsLog < Log form.get_question("rent_type", self)&.label_from_value(rent_type) end + def lettings? + true + end + def non_location_setup_questions_completed? [needstype, renewal, rent_type, startdate, owning_organisation_id, created_by_id].all?(&:present?) end diff --git a/app/services/csv/lettings_log_csv_service.rb b/app/services/csv/lettings_log_csv_service.rb index a24cb3706..30bdb6360 100644 --- a/app/services/csv/lettings_log_csv_service.rb +++ b/app/services/csv/lettings_log_csv_service.rb @@ -21,21 +21,31 @@ module Csv private - def label_from_value(record, att) + def label_from_value(record, att, is_codes_only_export:) if %w[la prevloc].include? att - label_from_boolean_value(record.send(att)) + record.send(att) elsif %w[mrcdate startdate voiddate].include? att record.send(att)&.to_formatted_s(:govuk_date) + elsif is_codes_only_export && (att.start_with?("location_", "scheme_")) + att = att + "_before_type_cast" unless %w[location_code scheme_code scheme_owning_organisation_name scheme_created_at location_startdate].include? att + value = record.send(att) else - record.form.get_question(att.remove("_label"), record)&.label_from_value(record.send(att.remove("_label"))) || label_from_boolean_value(record.send(att.remove("_label"))) + att = att.remove("_label", "_detail") # a couple of csv column headers have suffixes for the user that are not reflected in the app domain + field_value = record.send(att) + answer_label = record.form + .get_question(att, record) + &.label_from_value(field_value) + if is_codes_only_export + field_value + else + answer_label || label_if_boolean_value(field_value) || field_value + end end end - def label_from_boolean_value(value) + def label_if_boolean_value(value) return "Yes" if value == true return "No" if value == false - - value end def set_csv_attributes