From 77ddc2b92822f43817e61c32cb80c1da9855c81b Mon Sep 17 00:00:00 2001 From: Richard Worrall Date: Tue, 7 Jan 2025 12:44:50 +0000 Subject: [PATCH] [CPDNPQ-2437] Fix course calculator allowed_declaration_types --- app/services/statements/course_calculator.rb | 5 ++++- spec/services/statements/course_calculator_spec.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/services/statements/course_calculator.rb b/app/services/statements/course_calculator.rb index efa31558ca..633e303b27 100644 --- a/app/services/statements/course_calculator.rb +++ b/app/services/statements/course_calculator.rb @@ -65,7 +65,10 @@ def output_payment_subtotal end def allowed_declaration_types - course.schedule_for(cohort:).allowed_declaration_types.sort_by { Schedule::DECLARATION_TYPES.index(_1) } + Schedule.where(cohort:, course_group: course.course_group) + .flat_map(&:allowed_declaration_types) + .uniq + .sort_by { Schedule::DECLARATION_TYPES.index(_1) } end def declaration_count_for_declaration_type(declaration_type) diff --git a/spec/services/statements/course_calculator_spec.rb b/spec/services/statements/course_calculator_spec.rb index 0de917c1f2..c67660713b 100644 --- a/spec/services/statements/course_calculator_spec.rb +++ b/spec/services/statements/course_calculator_spec.rb @@ -329,6 +329,20 @@ end end + describe "#allowed_declaration_types" do + let(:course_group) { course.course_group } + + before do + course_group.schedules.destroy_all + create(:schedule, course_group:, cohort:, allowed_declaration_types: %w[started retained-1]) + create(:schedule, course_group:, cohort:, allowed_declaration_types: %w[retained-1 completed]) + end + + it "is derived from schedules" do + expect(subject.allowed_declaration_types).to eql(%w[started retained-1 completed]) + end + end + describe "#output_payment" do it "is a hash" do expect(subject.output_payment).to be_a(Hash)