Skip to content

Commit

Permalink
Génère le bordereau sans passer par un job
Browse files Browse the repository at this point in the history
Prépare l'édition du contenu des bordereaux
  • Loading branch information
goulvench committed Oct 28, 2024
1 parent 47b92ab commit d786bac
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 60 deletions.
13 changes: 1 addition & 12 deletions app/controllers/conservateurs/bordereaux_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ def create
@edifice = Edifice.find(params[:edifice])
raise unless @edifice.commune == @dossier.commune

@edifice.bordereau&.purge

GenerateBordereauPdfJob.perform_later(@dossier.id, @edifice.id)
@edifice.update!(bordereau_generation_enqueued_at: Time.zone.now)

respond_to do |format|
format.html do
redirect_to conservateurs_commune_bordereaux_path(@commune),
notice: "Le bordereau est en cours de génération …"
end
format.turbo_stream
end
@edifice.generate_bordereau!(@dossier)
end

protected
Expand Down
19 changes: 0 additions & 19 deletions app/jobs/generate_bordereau_pdf_job.rb

This file was deleted.

14 changes: 0 additions & 14 deletions app/jobs/sanity/checks_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,5 @@ def check_campaign_statuses_and_dates
AdminMailer.with(email: EMAIL, campaign:, text:).sanity_check_alert.deliver_later
end
end

def check_bordereaux_created
edifices_with_problems = Edifice
.where.missing(:bordereau_attachment)
.where("bordereau_generation_enqueued_at < ?", 5.minutes.ago)
.includes(:commune)

return if edifices_with_problems.empty?

text = "Les édifices suivants ont un bordereau en attente de génération depuis plus de 5 minutes : " \
"#{edifices_with_problems.pluck(:id).join(', ')}"
logger.info text
AdminMailer.with(email: EMAIL, text:).sanity_check_alert.deliver_later
end
end
end
6 changes: 6 additions & 0 deletions app/models/edifice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ def self.slug_for(nom_edifice)
def to_s
"Édifice #{nom} #{merimee_REF ? "(#{merimee_REF})" : '(sans référence Mérimée)'} - commune #{code_insee}"
end

def generate_bordereau!(dossier)
pdf = Bordereau::Pdf.new(dossier, self)
bordereau.purge if bordereau.attached?
bordereau.attach io: pdf.to_io, filename: pdf.filename, content_type: Mime[:pdf]
end
end
14 changes: 1 addition & 13 deletions app/views/conservateurs/bordereaux/_edifice.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,11 @@
%span
= "#{edifice.nom.upcase_first} · #{texte_nombre_objets_protégés(edifice)}"

- if edifice.bordereau.present?
- if edifice.bordereau.attached?
= link_to "Télécharger (PDF de #{number_to_human_size edifice.bordereau.byte_size})",
rails_blob_path(edifice.bordereau, disposition: "attachment"),
class: "fr-btn fr-btn--sm fr-btn--icon-left fr-icon-download-line",
title: "Bordereau de récolement · #{edifice.nom.upcase_first} (PDF de #{number_to_human_size edifice.bordereau.byte_size})"
= button_to "Regénérer",
conservateurs_commune_bordereaux_path(commune, edifice:),
method: :post,
class: "fr-btn fr-btn--sm fr-btn--secondary"
- elsif edifice.bordereau_generation_enqueued_at.present?
= render DsfrComponent::BadgeComponent.new status: :info do
Génération en cours
%span
Veuillez rafraichir cette page d’ici quelques minutes.
- if edifice.bordereau_generation_enqueued_at < 5.minutes.ago
%span
La génération prend beaucoup de temps, il y a peut-être un problème.
- else
= button_to "Générer le bordereau",
conservateurs_commune_bordereaux_path(commune, edifice:),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveBordereauGenerationEnqueuedAtFromEdifices < ActiveRecord::Migration[7.1]
def change
remove_column :edifices, :bordereau_generation_enqueued_at, :datetime
end
end
3 changes: 1 addition & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d786bac

Please sign in to comment.