fix: send_dossier_decision preview
This commit is contained in:
parent
ab0392fb36
commit
0e75f9960b
3 changed files with 22 additions and 6 deletions
|
@ -2,6 +2,7 @@ class ExpertMailer < ApplicationMailer
|
|||
helper MailerHelper
|
||||
layout 'mailers/layout'
|
||||
|
||||
# TODO: replace with v2 after MEP
|
||||
def send_dossier_decision(avis_id)
|
||||
@avis = Avis.eager_load(:dossier).find(avis_id)
|
||||
@dossier = @avis.dossier
|
||||
|
@ -11,6 +12,16 @@ class ExpertMailer < ApplicationMailer
|
|||
|
||||
mail(to: email, subject: subject)
|
||||
end
|
||||
|
||||
def send_dossier_decision_v2(avis)
|
||||
@avis = avis
|
||||
@dossier = @avis.dossier
|
||||
email = @avis.expert.email
|
||||
@decision = decision_dossier(@dossier)
|
||||
subject = "Dossier n° #{@dossier.id} a été #{@decision} - #{@dossier.procedure.libelle}"
|
||||
|
||||
mail(template_name: 'send_dossier_decision', to: email, subject: subject)
|
||||
end
|
||||
end
|
||||
|
||||
def decision_dossier(dossier)
|
||||
|
|
|
@ -1262,11 +1262,12 @@ class Dossier < ApplicationRecord
|
|||
.pluck('avis.id, experts_procedures.id')
|
||||
|
||||
# rubocop:disable Lint/UnusedBlockArgument
|
||||
avis_ids = avis_experts_procedures_ids
|
||||
avis = avis_experts_procedures_ids
|
||||
.uniq { |(avis_id, experts_procedures_id)| experts_procedures_id }
|
||||
.map { |(avis_id, _)| avis_id }
|
||||
.then { |avis_ids| Avis.find(avis_ids) }
|
||||
# rubocop:enable Lint/UnusedBlockArgument
|
||||
|
||||
avis_ids.each { |avis_id| ExpertMailer.send_dossier_decision(avis_id).deliver_later }
|
||||
avis.each { |a| ExpertMailer.send_dossier_decision_v2(a).deliver_later }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
class ExpertMailerPreview < ActionMailer::Preview
|
||||
def send_dossier_decision
|
||||
procedure = Procedure.new(libelle: 'Démarche pour faire des marches')
|
||||
procedure = Procedure.new(id: 1, libelle: 'Démarche pour faire des marches')
|
||||
dossier = Dossier.new(id: 1, procedure: procedure)
|
||||
|
||||
instructeur = Instructeur.new(id: 1, user: User.new(email: 'jeanmichel.de-chauvigny@exemple.fr'))
|
||||
expert = Expert.new(id: 1, user: User.new('moussa.kanga@exemple.fr'))
|
||||
|
||||
expert = Expert.new(id: 1, user: User.new(email: 'moussa.kanga@exemple.fr'))
|
||||
experts_procedure = ExpertsProcedure.new(expert: expert, procedure: procedure, allow_decision_access: true)
|
||||
avis = Avis.new(id: 1, email: 'test@exemple.fr', dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure)
|
||||
ExpertMailer.send_dossier_decision(avis.id)
|
||||
|
||||
avis = Avis.new(id: 1, email: 'test@exemple.fr', claimant: instructeur, dossier:, experts_procedure:, expert:)
|
||||
|
||||
ExpertMailer.send_dossier_decision_v2(avis)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue