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)