add service to create procedure archive

This commit is contained in:
Christophe Robillard 2021-03-29 22:15:49 +02:00
parent fba0d78153
commit 07cc4fa97f
6 changed files with 182 additions and 1 deletions

View file

@ -48,4 +48,12 @@ class Archive < ApplicationRecord
def available?
status == 'generated' && file.attached?
end
def filename(procedure)
if content_type == 'everything'
"procedure-#{procedure.id}.zip"
else
"procedure-#{procedure.id}-mois-#{I18n.l(month, format: '%Y-%m')}.zip"
end
end
end

View file

@ -172,7 +172,12 @@ class Dossier < ApplicationRecord
scope :en_construction, -> { not_archived.state_en_construction }
scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine }
scope :downloadable_sorted, -> {
scope :processed_in_month, -> (month) do
state_termine
.joins(:traitements)
.where(traitements: { processed_at: month.beginning_of_month..month.end_of_month })
end
scope :downloadable_sorted, -> {
state_not_brouillon
.includes(
:user,