convert date with dash for export renaming
This commit is contained in:
parent
9f504dbefd
commit
ac23d5fb41
4 changed files with 31 additions and 1 deletions
|
@ -307,7 +307,8 @@ module TagsSubstitutionConcern
|
||||||
|
|
||||||
def format_date(date)
|
def format_date(date)
|
||||||
if date.present?
|
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
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ class ExportTemplate < ApplicationRecord
|
||||||
validates_with ExportTemplateValidator
|
validates_with ExportTemplateValidator
|
||||||
|
|
||||||
DOSSIER_STATE = Dossier.states.fetch(:en_construction)
|
DOSSIER_STATE = Dossier.states.fetch(:en_construction)
|
||||||
|
FORMAT_DATE = "%Y-%m-%d"
|
||||||
|
|
||||||
def set_default_values
|
def set_default_values
|
||||||
content["default_dossier_directory"] = tiptap_json("dossier-")
|
content["default_dossier_directory"] = tiptap_json("dossier-")
|
||||||
|
|
|
@ -64,5 +64,25 @@ FactoryBot.define do
|
||||||
export_template.save
|
export_template.save
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -190,6 +190,14 @@ describe ExportTemplate do
|
||||||
it 'convert pdf_name' do
|
it 'convert pdf_name' do
|
||||||
expect(export_template.tiptap_convert(procedure.dossiers.first, "pdf_name")).to eq "mon_export_#{dossier.id}"
|
expect(export_template.tiptap_convert(procedure.dossiers.first, "pdf_name")).to eq "mon_export_#{dossier.id}"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#tiptap_convert_pj' do
|
describe '#tiptap_convert_pj' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue