From 772b1fcd68cc92d1472459bc01c11c5f3f25c604 Mon Sep 17 00:00:00 2001 From: carolynbarker <8038496+carolynbarker@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:02:27 +0000 Subject: [PATCH] CLDC-3911 Limit CSV variables to those defined in or before year (#2982) * don't use variables from the future * filter out nil elements for vars only defined in future * only group variables by name, not by description --------- Co-authored-by: Carolyn --- app/services/csv/lettings_log_csv_service.rb | 7 +++---- app/services/csv/sales_log_csv_service.rb | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/services/csv/lettings_log_csv_service.rb b/app/services/csv/lettings_log_csv_service.rb index 0a187d524..d7ab101ac 100644 --- a/app/services/csv/lettings_log_csv_service.rb +++ b/app/services/csv/lettings_log_csv_service.rb @@ -284,13 +284,12 @@ module Csv end def lettings_log_definitions - CsvVariableDefinition.lettings.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + CsvVariableDefinition.lettings.group_by(&:variable).map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) - end + options.select { |opt| opt.year < @year }.max_by(&:year) + }.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 08ce178e3..35adcf27f 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -179,13 +179,12 @@ module Csv end def sales_log_definitions - CsvVariableDefinition.sales.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + CsvVariableDefinition.sales.group_by(&:variable).map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) - end + options.select { |opt| opt.year < @year }.max_by(&:year) + }.compact end def insert_derived_and_related_attributes(ordered_questions)