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 @@ + + +
+ + +Date: {{ invoice_date }}
+Nom: {{ customer_name }}
+Email: {{ customer_email }}
+Adresse: {{ customer_address }}
+| Nom de l'article | +Quantité | +Prix unitaire | +Total | +
|---|---|---|---|
| {{ item.item_name }} | +{{ item.quantity }} | +{{ item.unit_price }} | +{{ item.quantity * item.unit_price }} | +
Montant Total: {{ total_amount }}
+Date: 2023-05-24
+Nom: Theresa Miller
+Email: wcabrera@example.net
+Adresse: 782 Rose Rest +Brandtside, WV 96174
+| Nom de l'article | +Quantité | +Prix unitaire | +Total | +
|---|---|---|---|
| we | +9 | +67 | +603 | +
| camera | +4 | +38 | +152 | +
| attack | +6 | +12 | +72 | +
| per | +9 | +39 | +351 | +
Montant Total: 6218
+Date: 2020-01-21
+Nom: Allison Hill
+Email: donaldgarcia@example.net
+Adresse: 600 Jeffery Parkways +New Jamesside, MT 29394
+| Nom de l'article | +Quantité | +Prix unitaire | +Total | +
|---|---|---|---|
| grow | +5 | +29 | +145 | +
| dinner | +6 | +23 | +138 | +
| best | +7 | +22 | +154 | +
| her | +6 | +87 | +522 | +
Montant Total: 2715
+Date: 2023-08-04
+Nom: Austin Gentry
+Email: jason76@example.net
+Adresse: 38849 Hurst Locks Suite 328 +Daviston, VI 14872
+| Nom de l'article | +Quantité | +Prix unitaire | +Total | +
|---|---|---|---|
| image | +7 | +86 | +602 | +
Montant Total: 9871
+Date: 2020-08-09
+Nom: Andrew Stevens
+Email: dudleynicholas@example.net
+Adresse: 310 Kendra Common Apt. 164 +Reidstad, GA 49021
+| Nom de l'article | +Quantité | +Prix unitaire | +Total | +
|---|---|---|---|
| shoulder | +4 | +30 | +120 | +
| maintain | +7 | +44 | +308 | +
| wish | +9 | +38 | +342 | +
| reveal | +6 | +17 | +102 | +
| drop | +1 | +50 | +50 | +
Montant Total: 2903
+Date: 2020-01-02
+Nom: Kendra Maddox DVM
+Email: frazierdanny@example.net
+Adresse: 46270 Stanton Track Apt. 814 +East Nathaniel, GA 71198
+| Nom de l'article | +Quantité | +Prix unitaire | +Total | +
|---|---|---|---|
| middle | +1 | +24 | +24 | +
| woman | +6 | +49 | +294 | +
| education | +1 | +40 | +40 | +
Montant Total: 9913
+