Skip to content

Commit

Permalink
Ajout de l'état 'cancelled' pour une 'PaymentRequest'
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Jan 17, 2025
1 parent 6b74cd8 commit 512398f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/controllers/schoolings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def confirm_abrogation; end
def cancellation_decision
Generate::CancellationDecisionJob.perform_now(@schooling)

@schooling.student.pfmps.each do |pfmp|
p_r = pfmp.latest_payment_request
p_r.transition_to!(:cancelled) if p_r.can_transition_to?(:cancelled)
end

redirect_to student_path(@schooling.student), notice: t("flash.da.cancellation", name: @schooling.student.full_name)
end

Expand Down
3 changes: 2 additions & 1 deletion app/decorators/asp/payment_request_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module PaymentRequestDecorator
integrated: :info,
rejected: :error,
paid: :success,
unpaid: :error
unpaid: :error,
cancelled: :error
}.freeze

ORDERED_FAILED_STATES = %i[incomplete rejected unpaid].freeze
Expand Down
7 changes: 7 additions & 0 deletions app/models/asp/payment_request_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class PaymentRequestStateMachine
state :pending, initial: true
state :incomplete
state :ready
state :cancelled
state :sent
state :rejected
state :integrated
Expand All @@ -27,6 +28,12 @@ class PaymentRequestStateMachine
transition from: :integrated, to: :paid
transition from: :integrated, to: :unpaid

transition from: :pending, to: :cancelled
transition from: :incomplete, to: :cancelled
transition from: :ready, to: :cancelled
transition from: :rejected, to: :cancelled
transition from: :unpaid, to: :cancelled

after_transition(from: :sent, to: :integrated) do |payment_request, transition|
attrs = transition.metadata

Expand Down
1 change: 1 addition & 0 deletions app/views/classes/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
= payment_requests_status_count_badge :pending, @classes_facade.nb_payment_requests(classe, %i[pending ready])
= payment_requests_status_count_badge :sent, @classes_facade.nb_payment_requests(classe, %i[sent integrated])
= payment_requests_status_count_badge :incomplete, @classes_facade.nb_payment_requests(classe, %i[incomplete rejected unpaid])
= payment_requests_status_count_badge :cancelled, @classes_facade.nb_payment_requests(classe, %i[cancelled])
= payment_requests_status_count_badge :paid, @classes_facade.nb_payment_requests(classe, %i[paid])
4 changes: 2 additions & 2 deletions app/views/pfmps/_pfmp_student_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
- if schooling.attributive_decision.attached?
= button_to "Télécharger la décision d'attribution", url_for(schooling.attributive_decision), class: 'fr-btn fr-btn--secondary', target: :download, method: :get
- if !schooling.cancellation_decision.attached?
= button_to "Retirer la décision d'attribution", confirm_cancellation_decision_school_year_class_schooling_path(school_year, classe, schooling), class: 'fr-btn fr-btn--danger', method: :get, disabled: true
= button_to "Retirer la décision d'attribution", confirm_cancellation_decision_school_year_class_schooling_path(school_year, classe, schooling), class: 'fr-btn fr-btn--danger', method: :get
= render partial: "shared/tooltip", locals: { message: "cancellation_decision", id: 1 }
- if schooling.abrogation_decision.attached?
= button_to "Télécharger la décision d'abrogation", url_for(schooling.abrogation_decision), class: 'fr-btn fr-btn--secondary', target: :download, method: :get
- if schooling.cancellation_decision.attached?
= button_to "Télécharger la décision de retrait", url_for(schooling.cancellation_decision), class: 'fr-btn fr-btn--secondary', target: :download, method: :get, disabled: true
= button_to "Télécharger la décision de retrait", url_for(schooling.cancellation_decision), class: 'fr-btn fr-btn--secondary', target: :download, method: :get
- if [email protected]_schooling.nil? && @student.current_schooling.eql?(schooling) && !schooling.removed?
= button_to "Masquer l'élève de la classe", confirm_removal_school_year_class_schooling_path(school_year, classe, schooling), class: 'fr-btn fr-btn--danger', method: :get
= render partial: "shared/tooltip", locals: { message: "remove_student", id: 1 }
3 changes: 3 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ fr:
rejected: "Demande rejetée"
paid: "Paiement envoyé"
unpaid: "Paiement échoué"
cancelled: "Annulée"
states:
pending: "En attente"
ready: "En attente"
Expand All @@ -329,6 +330,7 @@ fr:
rejected: "Demandes rejetées"
paid: "Paiements envoyés"
unpaid: "Paiements échoués"
cancelled: "Annulées"
state_explanations:
pending: |
La demande de paiement est prête à être traitée.
Expand All @@ -346,6 +348,7 @@ fr:
rejected: "La demande a été rejetée : %{rejected_reason}."
paid: Le paiement a été envoyé par l'agence comptable, et sera effectif dans un délai de un à trois jours ouvrables.
unpaid: "Le paiement a été refusé par l'agence comptable : %{unpaid_reason}."
cancelled: La demande de paiement est annulée suite au retrait de la décision d'attribution
ministries:
masa: Ministère de l'Agriculture et de la Souveraineté Alimentaire (MASA)
menj: Ministère de l'Éducation Nationale et de la Jeunesse (MENJ)
Expand Down

0 comments on commit 512398f

Please sign in to comment.