diff --git a/app/services/csv/lettings_log_csv_service.rb b/app/services/csv/lettings_log_csv_service.rb index 0a187d524..edf1b7edf 100644 --- a/app/services/csv/lettings_log_csv_service.rb +++ b/app/services/csv/lettings_log_csv_service.rb @@ -289,7 +289,7 @@ module Csv exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) + options.select { |opt| opt.year < @year }.max_by(&:year) end end diff --git a/app/services/csv/sales_log_csv_service.rb b/app/services/csv/sales_log_csv_service.rb index 08ce178e3..e30202e8b 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -184,7 +184,7 @@ module Csv exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) + options.select { |opt| opt.year < @year }.max_by(&:year) end end