From edb4c7414ddd93b30ae332889539febd311b818e Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 23 Aug 2022 14:07:29 +0100 Subject: [PATCH] choose year based on which case logs are downloaded --- app/models/case_log.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 639cf46b3..7acee13db 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -480,7 +480,10 @@ class CaseLog < ApplicationRecord def self.order_csv_attributes(initial_attributes) attributes = initial_attributes.clone - ordered_default_form_questions = move_checkbox_answer_options(FormHandler.instance.forms.first.second.questions) + downloaded_form_years = all.map(&:collection_start_year).uniq.compact + + downloaded_form_fields = if downloaded_form_years.count == 1 && downloaded_form_years[0].present? ? FormHandler.instance.get_form("#{downloaded_form_years[0]}_#{downloaded_form_years[0] + 1}").questions : FormHandler.instance.forms.first.second.questions + ordered_default_form_questions = move_checkbox_answer_options(downloaded_form_fields) attributes = (ordered_default_form_questions & attributes) + (attributes - ordered_default_form_questions) attributes = move_metadata_fields_to_front(attributes)