Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve generated pdf #126

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions app/models/shipment_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def to_s
Identifant éditeur (optionnel): #{external_id}

Identité pivot:
- Code Insee pays de naissance: #{pivot_identity.birth_country}
- Code Insee lieu de naissance: #{pivot_identity.birthplace}
- Date de naissance: #{pivot_identity.birthdate.strftime("%d/%m/%Y")}
- Nom de naissance: #{pivot_identity.last_name}
- Prénoms: #{pivot_identity.first_names.join(" ")}
- Sexe: #{(pivot_identity.gender == :female) ? "F" : "M"}
Code Insee pays de naissance: #{pivot_identity.birth_country}
Code Insee lieu de naissance: #{pivot_identity.birthplace}
Date de naissance: #{pivot_identity.birthdate.strftime("%d/%m/%Y")}
Nom de naissance: #{pivot_identity.last_name}
Prénoms: #{pivot_identity.first_names.join(" ")}
Sexe: #{(pivot_identity.gender == :female) ? "F" : "M"}

#{quotient_familial_text}
TEXT
Expand All @@ -54,20 +54,20 @@ def quotient_familial_text
ERREUR: #{I18n.t("shipments.qf_v1_error.title")}
TEXT
else
<<~TEXT
Quotient familial:
- Régime: #{quotient_familial["regime"]}
- Année: #{quotient_familial["annee"]}
- Mois: #{quotient_familial["mois"]}
- Quotient familial: #{quotient_familial["quotientFamilial"]}
- Allocataires:
#{allocataire_text}
- Enfants:
#{enfants_text}
TEXT
[
"Quotient familial:",
" Régime: #{quotient_familial["regime"]}",
" Année: #{quotient_familial["annee"]}",
" Mois: #{quotient_familial["mois"]}",
" Quotient familial: #{quotient_familial["quotientFamilial"]}",
"",
" Allocataires:",
"",
allocataire_text,
" Enfants:",
"",
enfants_text,
].join("\n")
end
end

Expand All @@ -80,28 +80,28 @@ def enfants_text
end

def people_text(people)
return "Aucun" if people.blank?
return "Aucun\n\n" if people.blank?

people.map { |person| person_text(person) }.join("\n")
end

def person_text(person)
<<~TEXT
#{names(person)}
- Date de naissance: #{person["jourDateDeNaissance"]}/#{person["moisDateDeNaissance"]}/#{person["anneeDateDeNaissance"]}
- Sexe: #{person["sexe"]}

TEXT
[
names(person),
" Date de naissance: #{person["jourDateDeNaissance"]}/#{person["moisDateDeNaissance"]}/#{person["anneeDateDeNaissance"]}",
" Sexe: #{person["sexe"]}",
"",
].flatten.join("\n")
end

def names(person)
if quotient_familial["version"] == "v1"
"- Noms et prénoms : #{person["nomPrenom"]}"
" - Noms et prénoms : #{person["nomPrenom"]}"
else
[
"- Nom de naissance: #{person["nomNaissance"]}",
"- Nom d'usage: #{person["nomUsuel"]}",
"- Prénoms: #{person["prenoms"]}",
" - Nom de naissance: #{person["nomNaissance"]}",
" Nom d'usage: #{person["nomUsuel"]}",
" Prénoms: #{person["prenoms"]}",
].join("\n")
end
end
Expand Down
10 changes: 10 additions & 0 deletions scripts/insert_test_collectivities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
collectivities = [
{siret: "21040107100019", code_cog: "04107", name: "Majastres", departement: "04", status: :active},
{siret: "11111111111111", code_cog: "11111", name: "Commune de HubEE - Test", departement: "11", status: :active},
{siret: "11111111111112", code_cog: "11112", name: "Commune de HubEE - API", departement: "11", status: :active},
]

collectivities.each do |collectivity|
c = Collectivity.new(**collectivity)
c.save(validate: false)
end
42 changes: 0 additions & 42 deletions scritps/insert_6_collectivities.rb

This file was deleted.

53 changes: 51 additions & 2 deletions spec/models/shipment_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,41 @@
subject(:human_readable_string) { shipment_data.to_s }

let(:expected_string) do
"Identifant éditeur (optionnel): external_id\n\nIdentité pivot:\n - Code Insee pays de naissance: 99135\n - Code Insee lieu de naissance: \n - Date de naissance: 15/10/1979\n - Nom de naissance: Heinemeier Hansson\n - Prénoms: David\n - Sexe: M\n\nQuotient familial:\n - Régime: CNAF\n - Année: 2024\n - Mois: 2\n - Quotient familial: 2550\n - Allocataires:\n \n - Nom de naissance: DUBOIS\n- Nom d'usage: DUBOIS\n- Prénoms: ANGELA\n- Date de naissance: 24/08/1962\n- Sexe: F\n\n\n \n - Enfants:\n \n - Nom de naissance: Dujardin\n- Nom d'usage: Dujardin\n- Prénoms: Jean\n- Date de naissance: 13/12/2016\n- Sexe: M\n\n\n\n"
[
"Identifant éditeur (optionnel): external_id",
"",
"Identité pivot:",
" Code Insee pays de naissance: 99135",
" Code Insee lieu de naissance: ",
" Date de naissance: 15/10/1979",
" Nom de naissance: Heinemeier Hansson",
" Prénoms: David",
" Sexe: M",
"",
"Quotient familial:",
" Régime: CNAF",
" Année: 2024",
" Mois: 2",
" Quotient familial: 2550",
"",
" Allocataires:",
"",
" - Nom de naissance: DUBOIS",
" Nom d'usage: DUBOIS",
" Prénoms: ANGELA",
" Date de naissance: 24/08/1962",
" Sexe: F",
"",
" Enfants:",
"",
" - Nom de naissance: Dujardin",
" Nom d'usage: Dujardin",
" Prénoms: Jean",
" Date de naissance: 13/12/2016",
" Sexe: M",
"",
"",
].join("\n")
end

it "returns the shipment data as a string" do
Expand All @@ -79,7 +113,22 @@
let(:quotient_familial) { {} }

let(:expected_string) do
"Identifant éditeur (optionnel): external_id\n\nIdentité pivot:\n - Code Insee pays de naissance: 99135\n - Code Insee lieu de naissance: \n - Date de naissance: 15/10/1979\n - Nom de naissance: Heinemeier Hansson\n - Prénoms: David\n - Sexe: M\n\nQuotient familial:\n ERREUR: La récupération de votre quotient familial n'a pas fonctionné\n\n"
[
"Identifant éditeur (optionnel): external_id",
"",
"Identité pivot:",
" Code Insee pays de naissance: 99135",
" Code Insee lieu de naissance: ",
" Date de naissance: 15/10/1979",
" Nom de naissance: Heinemeier Hansson",
" Prénoms: David",
" Sexe: M",
"",
"Quotient familial:",
" ERREUR: La récupération de votre quotient familial n'a pas fonctionné",
"",
"",
].join("\n")
end

it "returns the shipment data as a string with the error" do
Expand Down