diff --git a/app/controllers/sac_cas/event/participations_controller.rb b/app/controllers/sac_cas/event/participations_controller.rb index 678d7ac78..953b07bb7 100644 --- a/app/controllers/sac_cas/event/participations_controller.rb +++ b/app/controllers/sac_cas/event/participations_controller.rb @@ -20,10 +20,10 @@ module SacCas::Event::ParticipationsController after_summon :enqueue_invoice_job after_assign :enqueue_confirmation_job # send_confirmation_email in core checks current_user_interested_in_mail? which should be irrelevant here before_cancel :assert_participant_cancelable? - after_cancel :cancel_invoices end def cancel + cancel_invoices entry.cancel_statement = params.dig(:event_participation, :cancel_statement) entry.canceled_at = params.dig(:event_participation, :canceled_at) || Time.zone.today entry.canceled_at = Time.zone.today if participant_cancels? @@ -182,6 +182,6 @@ def cancel_invoices Invoices::Abacus::CancelInvoiceJob.new(invoice).enqueue! end - ExternalInvoice::CourseAnnulation.invoice!(entry) + ExternalInvoice::CourseAnnulation.invoice!(entry) unless entry.state == "applied" end end diff --git a/spec/controllers/event/participations_controller_spec.rb b/spec/controllers/event/participations_controller_spec.rb index cd49a4085..1c3bd915d 100644 --- a/spec/controllers/event/participations_controller_spec.rb +++ b/spec/controllers/event/participations_controller_spec.rb @@ -481,6 +481,15 @@ expect(invoice.state).to eq("draft") expect(invoice.year).to eq(event.dates.first.start_at.year) end + + it "PUT#cancel does not create course annulation invoice when participation state is applied" do + participation.update!(price: 10, price_category: :price_regular) + participation.update_column(:state, :applied) + + expect do + put :cancel, params: params.merge({event_participation: {canceled_at: 1.day.ago}}) + end.not_to change { ExternalInvoice::CourseAnnulation.count } + end end describe "PUT#update" do