Skip to content

Commit

Permalink
Do no create annulation invoice when state is applied (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi committed Jan 29, 2025
1 parent 510584d commit 6a181b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/sac_cas/event/participations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ 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
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?
cancel_invoices
change_state("canceled", "cancel")
end

Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/controllers/event/participations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a181b4

Please sign in to comment.