From a559513939bbbc68ca53b854c212af0271121877 Mon Sep 17 00:00:00 2001 From: Carolyn Date: Mon, 10 Mar 2025 22:13:58 +0000 Subject: [PATCH] filter out nil elements for vars only defined in future --- app/services/csv/lettings_log_csv_service.rb | 4 ++-- app/services/csv/sales_log_csv_service.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/csv/lettings_log_csv_service.rb b/app/services/csv/lettings_log_csv_service.rb index edf1b7edf..f11f7f7d9 100644 --- a/app/services/csv/lettings_log_csv_service.rb +++ b/app/services/csv/lettings_log_csv_service.rb @@ -285,12 +285,12 @@ module Csv def lettings_log_definitions CsvVariableDefinition.lettings.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + .map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match options.select { |opt| opt.year < @year }.max_by(&:year) - end + }.compact end def insert_derived_and_related_attributes(ordered_questions) diff --git a/app/services/csv/sales_log_csv_service.rb b/app/services/csv/sales_log_csv_service.rb index e30202e8b..c0150c7ca 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -180,12 +180,12 @@ module Csv def sales_log_definitions CsvVariableDefinition.sales.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + .map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match options.select { |opt| opt.year < @year }.max_by(&:year) - end + }.compact end def insert_derived_and_related_attributes(ordered_questions)