From 3c01502c4f50992551e7e61a4c97b584c4ff8d6e Mon Sep 17 00:00:00 2001 From: gwen Date: Mon, 3 Mar 2025 13:09:01 +0100 Subject: [PATCH] invoice templating --- invoice_templating/doc.md | 74 +++++++++++ invoice_templating/generate_invoices.py | 23 ++++ invoice_templating/import json.py | 43 +++++++ invoice_templating/invoice_data.json | 137 +++++++++++++++++++++ invoice_templating/invoice_template.html | 56 +++++++++ invoice_templating/invoices/invoice_1.html | 78 ++++++++++++ invoice_templating/invoices/invoice_2.html | 78 ++++++++++++ invoice_templating/invoices/invoice_3.html | 57 +++++++++ invoice_templating/invoices/invoice_4.html | 85 +++++++++++++ invoice_templating/invoices/invoice_5.html | 71 +++++++++++ invoice_templating/product_generation.py | 32 +++++ invoice_templating/produits_sport.json | 72 +++++++++++ 12 files changed, 806 insertions(+) create mode 100644 invoice_templating/doc.md create mode 100644 invoice_templating/generate_invoices.py create mode 100644 invoice_templating/import json.py create mode 100644 invoice_templating/invoice_data.json create mode 100644 invoice_templating/invoice_template.html create mode 100644 invoice_templating/invoices/invoice_1.html create mode 100644 invoice_templating/invoices/invoice_2.html create mode 100644 invoice_templating/invoices/invoice_3.html create mode 100644 invoice_templating/invoices/invoice_4.html create mode 100644 invoice_templating/invoices/invoice_5.html create mode 100644 invoice_templating/product_generation.py create mode 100644 invoice_templating/produits_sport.json diff --git a/invoice_templating/doc.md b/invoice_templating/doc.md new file mode 100644 index 0000000..68ac836 --- /dev/null +++ b/invoice_templating/doc.md @@ -0,0 +1,74 @@ +Voici une documentation technique détaillée pour la fonction `generer_produits`, incluant une description détaillée et des exemples d'usage : + +### Documentation Technique + +#### Fonction : `generer_produits` + +**Description :** +La fonction `generer_produits` génère une liste de produits d'articles de sport fictifs. Chaque produit est représenté par un dictionnaire contenant des informations telles que le nom, la marque, le prix, la description et la disponibilité. Cette fonction utilise la bibliothèque `Faker` pour générer des données aléatoires réalistes. + +**Arguments :** +- `nombre` (int) : Le nombre de produits à générer. + +**Retourne :** +- `list` : Une liste de dictionnaires, où chaque dictionnaire représente un produit avec les clés suivantes : +- `nom` (str) : Le nom du produit. +- `marque` (str) : La marque du produit. +- `prix` (float) : Le prix du produit. +- `description` (str) : Une description du produit. +- `disponible` (bool) : La disponibilité du produit. + +**Usage :** +La fonction `generer_produits` est utile pour créer rapidement un ensemble de données fictives pour des tests ou des démonstrations. Elle peut être utilisée dans des scripts de test, des simulations de base de données, ou pour peupler des interfaces utilisateur avec des exemples de produits. + +**Exemple d'utilisation :** + +```python +# Importer la fonction +from votre_module import generer_produits + +# Générer 5 produits +produits = generer_produits(5) + +# Afficher les produits générés +for produit in produits: + print(produit) +``` + +**Exemple de sortie :** + +```python +{ + 'nom': 'Vélo Rapide', + 'marque': 'SportMax', + 'prix': 299.99, + 'description': 'Un vélo rapide pour les courses.', + 'disponible': True +} +{ + 'nom': 'Raquettes Pro', + 'marque': 'RaquettesPro', + 'prix': 129.99, + 'description': 'Des raquettes professionnelles pour le tennis.', + 'disponible': False +} +... +``` + +**Considérations :** +- La fonction utilise des listes prédéfinies de catégories et de marques pour générer des produits variés. Vous pouvez personnaliser ces listes pour mieux correspondre à vos besoins. +- Les prix sont générés aléatoirement entre 10 et 500 euros. Vous pouvez ajuster cette plage si nécessaire. +- La disponibilité des produits est déterminée aléatoirement. + +**Dépendances :** +- La fonction nécessite la bibliothèque `Faker`. Vous pouvez l'installer via pip : + ```bash + pip install faker + ``` + +**Limitations :** +- Les données générées sont fictives et ne doivent pas être utilisées pour des applications réelles sans vérification. +- La fonction ne vérifie pas la validité des noms de produits ou des descriptions générées. + +**Conclusion :** +La fonction `generer_produits` est un outil pratique pour générer rapidement des données de test réalistes pour des articles de sport. Elle peut être facilement intégrée dans des scripts de test ou des applications de démonstration. diff --git a/invoice_templating/generate_invoices.py b/invoice_templating/generate_invoices.py new file mode 100644 index 0000000..1629109 --- /dev/null +++ b/invoice_templating/generate_invoices.py @@ -0,0 +1,23 @@ +import os +import json +from jinja2 import Environment, FileSystemLoader + +# Charger les données JSON +with open('invoice_data.json', 'r') as file: + invoice_data = json.load(file) + +# Configurer Jinja2 +env = Environment(loader=FileSystemLoader('.')) +template = env.get_template('invoice_template.html') + +# Créer le dossier 'facture' s'il n'existe pas +os.makedirs('facture', exist_ok=True) + +# Générer les fichiers HTML pour chaque facture +for data in invoice_data: + html_output = template.render(data) + invoice_filename = f"invoices/{data['invoice_number']}.html" + with open(invoice_filename, 'w') as file: + file.write(html_output) + +print("Les factures ont été générées dans le dossier 'facture'.") \ No newline at end of file diff --git a/invoice_templating/import json.py b/invoice_templating/import json.py new file mode 100644 index 0000000..1348d0b --- /dev/null +++ b/invoice_templating/import json.py @@ -0,0 +1,43 @@ +import json +from faker import Faker + +# Initialiser Faker avec un seed pour la reproductibilité +fake = Faker() +Faker.seed(42) + +# Fonction pour générer des données de facturation client +def generate_invoice_data(num_customers=5): + invoice_data = [] + + for _ in range(num_customers): + customer_data = { + "customer_name": fake.name(), + "customer_email": fake.email(), + "customer_address": fake.address(), + "invoice_number": fake.uuid4(), + "invoice_date": fake.date_this_decade().isoformat(), + "total_amount": fake.random_int(min=100, max=10000, step=1), + "items": [ + { + "item_name": fake.word(), + "quantity": fake.random_int(min=1, max=10), + "unit_price": fake.random_int(min=10, max=100), + } + for _ in range(fake.random_int(min=1, max=5)) + ] + } + invoice_data.append(customer_data) + + return invoice_data + +# Générer les données de facturation +invoice_data = generate_invoice_data() + +# Convertir les données en JSON +invoice_json = json.dumps(invoice_data, indent=4) + +# Enregistrer le JSON dans un fichier +with open('invoice_data.json', 'w') as file: + file.write(invoice_json) + +print("Les données de facturation ont été enregistrées dans 'invoice_data.json'.") diff --git a/invoice_templating/invoice_data.json b/invoice_templating/invoice_data.json new file mode 100644 index 0000000..39ea5ff --- /dev/null +++ b/invoice_templating/invoice_data.json @@ -0,0 +1,137 @@ +[ + { + "customer_name": "Allison Hill", + "customer_email": "donaldgarcia@example.net", + "customer_address": "600 Jeffery Parkways\nNew Jamesside, MT 29394", + "invoice_number": "cf36d58b-4737-4190-96da-1dac72ff5d2a", + "invoice_date": "2020-01-21", + "total_amount": 2715, + "items": [ + { + "item_name": "grow", + "quantity": 5, + "unit_price": 29 + }, + { + "item_name": "dinner", + "quantity": 6, + "unit_price": 23 + }, + { + "item_name": "best", + "quantity": 7, + "unit_price": 22 + }, + { + "item_name": "her", + "quantity": 6, + "unit_price": 87 + } + ] + }, + { + "customer_name": "Andrew Stevens", + "customer_email": "dudleynicholas@example.net", + "customer_address": "310 Kendra Common Apt. 164\nReidstad, GA 49021", + "invoice_number": "4458a885-ab90-49a4-b5a2-40ae5af30553", + "invoice_date": "2020-08-09", + "total_amount": 2903, + "items": [ + { + "item_name": "shoulder", + "quantity": 4, + "unit_price": 30 + }, + { + "item_name": "maintain", + "quantity": 7, + "unit_price": 44 + }, + { + "item_name": "wish", + "quantity": 9, + "unit_price": 38 + }, + { + "item_name": "reveal", + "quantity": 6, + "unit_price": 17 + }, + { + "item_name": "drop", + "quantity": 1, + "unit_price": 50 + } + ] + }, + { + "customer_name": "Austin Gentry", + "customer_email": "jason76@example.net", + "customer_address": "38849 Hurst Locks Suite 328\nDaviston, VI 14872", + "invoice_number": "cac5b68c-28f4-4481-a0a0-4dc427209bdf", + "invoice_date": "2023-08-04", + "total_amount": 9871, + "items": [ + { + "item_name": "image", + "quantity": 7, + "unit_price": 86 + } + ] + }, + { + "customer_name": "Kendra Maddox DVM", + "customer_email": "frazierdanny@example.net", + "customer_address": "46270 Stanton Track Apt. 814\nEast Nathaniel, GA 71198", + "invoice_number": "87c5421e-ec24-43c5-8754-108ff4188f3f", + "invoice_date": "2020-01-02", + "total_amount": 9913, + "items": [ + { + "item_name": "middle", + "quantity": 1, + "unit_price": 24 + }, + { + "item_name": "woman", + "quantity": 6, + "unit_price": 49 + }, + { + "item_name": "education", + "quantity": 1, + "unit_price": 40 + } + ] + }, + { + "customer_name": "Theresa Miller", + "customer_email": "wcabrera@example.net", + "customer_address": "782 Rose Rest\nBrandtside, WV 96174", + "invoice_number": "4fcca39a-b683-42e6-b37e-a2dfb09b2a5c", + "invoice_date": "2023-05-24", + "total_amount": 6218, + "items": [ + { + "item_name": "we", + "quantity": 9, + "unit_price": 67 + }, + { + "item_name": "camera", + "quantity": 4, + "unit_price": 38 + }, + { + "item_name": "attack", + "quantity": 6, + "unit_price": 12 + }, + { + "item_name": "per", + "quantity": 9, + "unit_price": 39 + } + ] + } +] \ No newline at end of file diff --git a/invoice_templating/invoice_template.html b/invoice_templating/invoice_template.html new file mode 100644 index 0000000..e51e1f9 --- /dev/null +++ b/invoice_templating/invoice_template.html @@ -0,0 +1,56 @@ + + + + + + Facture {{ invoice_number }} + + + +
+
+

Facture {{ invoice_number }}

+

Date: {{ invoice_date }}

+
+
+

Informations Client

+

Nom: {{ customer_name }}

+

Email: {{ customer_email }}

+

Adresse: {{ customer_address }}

+
+
+

Articles

+ + + + + + + + {% for item in items %} + + + + + + + {% endfor %} +
Nom de l'articleQuantitéPrix unitaireTotal
{{ item.item_name }}{{ item.quantity }}{{ item.unit_price }}{{ item.quantity * item.unit_price }}
+
+
+

Montant Total: {{ total_amount }}

+
+ +
+ + diff --git a/invoice_templating/invoices/invoice_1.html b/invoice_templating/invoices/invoice_1.html new file mode 100644 index 0000000..331f9c2 --- /dev/null +++ b/invoice_templating/invoices/invoice_1.html @@ -0,0 +1,78 @@ + + + + + + Facture 4fcca39a-b683-42e6-b37e-a2dfb09b2a5c + + + +
+
+

Facture 4fcca39a-b683-42e6-b37e-a2dfb09b2a5c

+

Date: 2023-05-24

+
+
+

Informations Client

+

Nom: Theresa Miller

+

Email: wcabrera@example.net

+

Adresse: 782 Rose Rest +Brandtside, WV 96174

+
+
+

Articles

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Nom de l'articleQuantitéPrix unitaireTotal
we967603
camera438152
attack61272
per939351
+
+
+

Montant Total: 6218

+
+ +
+ + \ No newline at end of file diff --git a/invoice_templating/invoices/invoice_2.html b/invoice_templating/invoices/invoice_2.html new file mode 100644 index 0000000..879815b --- /dev/null +++ b/invoice_templating/invoices/invoice_2.html @@ -0,0 +1,78 @@ + + + + + + Facture cf36d58b-4737-4190-96da-1dac72ff5d2a + + + +
+
+

Facture cf36d58b-4737-4190-96da-1dac72ff5d2a

+

Date: 2020-01-21

+
+
+

Informations Client

+

Nom: Allison Hill

+

Email: donaldgarcia@example.net

+

Adresse: 600 Jeffery Parkways +New Jamesside, MT 29394

+
+
+

Articles

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Nom de l'articleQuantitéPrix unitaireTotal
grow529145
dinner623138
best722154
her687522
+
+
+

Montant Total: 2715

+
+ +
+ + \ No newline at end of file diff --git a/invoice_templating/invoices/invoice_3.html b/invoice_templating/invoices/invoice_3.html new file mode 100644 index 0000000..2d66286 --- /dev/null +++ b/invoice_templating/invoices/invoice_3.html @@ -0,0 +1,57 @@ + + + + + + Facture cac5b68c-28f4-4481-a0a0-4dc427209bdf + + + +
+
+

Facture cac5b68c-28f4-4481-a0a0-4dc427209bdf

+

Date: 2023-08-04

+
+
+

Informations Client

+

Nom: Austin Gentry

+

Email: jason76@example.net

+

Adresse: 38849 Hurst Locks Suite 328 +Daviston, VI 14872

+
+
+

Articles

+ + + + + + + + + + + + + + + +
Nom de l'articleQuantitéPrix unitaireTotal
image786602
+
+
+

Montant Total: 9871

+
+ +
+ + \ No newline at end of file diff --git a/invoice_templating/invoices/invoice_4.html b/invoice_templating/invoices/invoice_4.html new file mode 100644 index 0000000..35a5374 --- /dev/null +++ b/invoice_templating/invoices/invoice_4.html @@ -0,0 +1,85 @@ + + + + + + Facture 4458a885-ab90-49a4-b5a2-40ae5af30553 + + + +
+
+

Facture 4458a885-ab90-49a4-b5a2-40ae5af30553

+

Date: 2020-08-09

+
+
+

Informations Client

+

Nom: Andrew Stevens

+

Email: dudleynicholas@example.net

+

Adresse: 310 Kendra Common Apt. 164 +Reidstad, GA 49021

+
+
+

Articles

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Nom de l'articleQuantitéPrix unitaireTotal
shoulder430120
maintain744308
wish938342
reveal617102
drop15050
+
+
+

Montant Total: 2903

+
+ +
+ + \ No newline at end of file diff --git a/invoice_templating/invoices/invoice_5.html b/invoice_templating/invoices/invoice_5.html new file mode 100644 index 0000000..8428173 --- /dev/null +++ b/invoice_templating/invoices/invoice_5.html @@ -0,0 +1,71 @@ + + + + + + Facture 87c5421e-ec24-43c5-8754-108ff4188f3f + + + +
+
+

Facture 87c5421e-ec24-43c5-8754-108ff4188f3f

+

Date: 2020-01-02

+
+
+

Informations Client

+

Nom: Kendra Maddox DVM

+

Email: frazierdanny@example.net

+

Adresse: 46270 Stanton Track Apt. 814 +East Nathaniel, GA 71198

+
+
+

Articles

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Nom de l'articleQuantitéPrix unitaireTotal
middle12424
woman649294
education14040
+
+
+

Montant Total: 9913

+
+ +
+ + \ No newline at end of file diff --git a/invoice_templating/product_generation.py b/invoice_templating/product_generation.py new file mode 100644 index 0000000..35fe254 --- /dev/null +++ b/invoice_templating/product_generation.py @@ -0,0 +1,32 @@ +from faker import Faker +import random +import asyncio + +# Initialiser Faker +fake = Faker('fr_FR') + +# Liste de catégories de produits +categories = ['vélo', 'raquettes', 'chaussures', 'ballons', 'sacs de sport', 'équipements de fitness'] + +# Liste de marques fictives +marques = ['SportMax', 'FitLife', 'AthléTech', 'VéloRapide', 'RaquettesPro', 'ChaussSport'] + +async def generer_produits(nombre): + """ + Génère un nombre spécifié de produits fictifs d'articles de sport de manière asynchrone. + + Args: + nombre (int): Le nombre de produits à générer. + + Yields: + dict: Un dictionnaire représentant un produit. + """ + for _ in range(nombre): + produit = { + 'nom': fake.word() + ' ' + random.choice(categories), + 'marque': random.choice(marques), + 'prix': round(random.uniform(10, 500), 2), + 'description': fake.sentence(), + 'disponible': fake.boolean() + } + yield produit diff --git a/invoice_templating/produits_sport.json b/invoice_templating/produits_sport.json new file mode 100644 index 0000000..e7820c1 --- /dev/null +++ b/invoice_templating/produits_sport.json @@ -0,0 +1,72 @@ +[ + { + "nom": "objet chaussures", + "marque": "ChaussSport", + "prix": 249.63, + "description": "Crier oser médecin drame jusque lieu espèce poids.", + "disponible": false + }, + { + "nom": "père équipements de fitness", + "marque": "AthléTech", + "prix": 151.13, + "description": "Village mériter sentir avouer passion habiter revoir chasser.", + "disponible": false + }, + { + "nom": "éclater ballons", + "marque": "AthléTech", + "prix": 35.69, + "description": "Réclamer seulement qui aide claire.", + "disponible": false + }, + { + "nom": "ouvrage ballons", + "marque": "AthléTech", + "prix": 41.59, + "description": "Source rapide bande liberté réclamer fin possible.", + "disponible": true + }, + { + "nom": "rapide ballons", + "marque": "RaquettesPro", + "prix": 243.23, + "description": "Ville quart président solitude tôt centre.", + "disponible": true + }, + { + "nom": "monde vélo", + "marque": "RaquettesPro", + "prix": 84.76, + "description": "Quart jeune d'autres épais caractère ancien ah marier.", + "disponible": true + }, + { + "nom": "goutte chaussures", + "marque": "FitLife", + "prix": 227.29, + "description": "Rejeter rouler droit bruit réclamer.", + "disponible": false + }, + { + "nom": "parmi vélo", + "marque": "ChaussSport", + "prix": 84.09, + "description": "Main crise arrivée.", + "disponible": true + }, + { + "nom": "cent sacs de sport", + "marque": "ChaussSport", + "prix": 170.78, + "description": "Éviter retomber miser etc vrai serrer parfaitement eau.", + "disponible": false + }, + { + "nom": "partir chaussures", + "marque": "ChaussSport", + "prix": 62.13, + "description": "Solitude ce défaut.", + "disponible": false + } +] \ No newline at end of file