convert date with dash for export renaming

This commit is contained in:
Christophe Robillard 2024-06-04 10:19:15 +02:00
parent 9f504dbefd
commit ac23d5fb41
4 changed files with 31 additions and 1 deletions

View file

@ -307,7 +307,8 @@ module TagsSubstitutionConcern
def format_date(date)
if date.present?
date.strftime('%d/%m/%Y')
format = defined?(self.class::FORMAT_DATE) ? self.class::FORMAT_DATE : '%d/%m/%Y'
date.strftime(format)
else
''
end

View file

@ -7,6 +7,7 @@ class ExportTemplate < ApplicationRecord
validates_with ExportTemplateValidator
DOSSIER_STATE = Dossier.states.fetch(:en_construction)
FORMAT_DATE = "%Y-%m-%d"
def set_default_values
content["default_dossier_directory"] = tiptap_json("dossier-")

View file

@ -64,5 +64,25 @@ FactoryBot.define do
export_template.save
end
end
trait :with_date_depot_for_export_pdf do
to_create do |export_template, _|
export_template.set_default_values
export_template.content["pdf_name"]["content"] = [
{
"type" => "paragraph",
"content" =>
[
{ "text" => "export_", "type" => "text" },
{ "type" => "mention", "attrs" => { "id" => "dossier_number", "label" => "numéro du dossier" } },
{ "text" => "-", "type" => "text" },
{ "type" => "mention", "attrs" => { "id" => "dossier_depose_at", "label" => "date de dépôt" } },
{ "text" => " ", "type" => "text" }
]
}
]
export_template.save
end
end
end
end

View file

@ -190,6 +190,14 @@ describe ExportTemplate do
it 'convert pdf_name' do
expect(export_template.tiptap_convert(procedure.dossiers.first, "pdf_name")).to eq "mon_export_#{dossier.id}"
end
context 'for date' do
let(:export_template) { create(:export_template, :with_date_depot_for_export_pdf, groupe_instructeur:) }
let(:dossier) { create(:dossier, :en_construction, procedure:, depose_at: Date.parse("2024/03/30")) }
it 'convert date with dash' do
expect(export_template.tiptap_convert(dossier, "pdf_name")).to eq "export_#{dossier.id}-2024-03-30"
end
end
end
describe '#tiptap_convert_pj' do