invoice templating

main
gwen 1 year ago
parent 2feadab0fe
commit 3c01502c4f

@ -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.

@ -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'.")

@ -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'.")

@ -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
}
]
}
]

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facture {{ invoice_number }}</title>
<style>
body { font-family: Arial, sans-serif; }
.invoice { width: 80%; margin: auto; border: 1px solid #ddd; padding: 20px; }
.header, .footer { text-align: center; }
.customer-info, .items { margin-bottom: 20px; }
.items table { width: 100%; border-collapse: collapse; }
.items table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.total { text-align: right; font-weight: bold; }
</style>
</head>
<body>
<div class="invoice">
<div class="header">
<h1>Facture {{ invoice_number }}</h1>
<p>Date: {{ invoice_date }}</p>
</div>
<div class="customer-info">
<h2>Informations Client</h2>
<p>Nom: {{ customer_name }}</p>
<p>Email: {{ customer_email }}</p>
<p>Adresse: {{ customer_address }}</p>
</div>
<div class="items">
<h2>Articles</h2>
<table>
<tr>
<th>Nom de l'article</th>
<th>Quantité</th>
<th>Prix unitaire</th>
<th>Total</th>
</tr>
{% for item in items %}
<tr>
<td>{{ item.item_name }}</td>
<td>{{ item.quantity }}</td>
<td>{{ item.unit_price }}</td>
<td>{{ item.quantity * item.unit_price }}</td>
</tr>
{% endfor %}
</table>
</div>
<div class="total">
<p>Montant Total: {{ total_amount }}</p>
</div>
<div class="footer">
<p>Merci pour votre achat!</p>
</div>
</div>
</body>
</html>

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facture 4fcca39a-b683-42e6-b37e-a2dfb09b2a5c</title>
<style>
body { font-family: Arial, sans-serif; }
.invoice { width: 80%; margin: auto; border: 1px solid #ddd; padding: 20px; }
.header, .footer { text-align: center; }
.customer-info, .items { margin-bottom: 20px; }
.items table { width: 100%; border-collapse: collapse; }
.items table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.total { text-align: right; font-weight: bold; }
</style>
</head>
<body>
<div class="invoice">
<div class="header">
<h1>Facture 4fcca39a-b683-42e6-b37e-a2dfb09b2a5c</h1>
<p>Date: 2023-05-24</p>
</div>
<div class="customer-info">
<h2>Informations Client</h2>
<p>Nom: Theresa Miller</p>
<p>Email: wcabrera@example.net</p>
<p>Adresse: 782 Rose Rest
Brandtside, WV 96174</p>
</div>
<div class="items">
<h2>Articles</h2>
<table>
<tr>
<th>Nom de l'article</th>
<th>Quantité</th>
<th>Prix unitaire</th>
<th>Total</th>
</tr>
<tr>
<td>we</td>
<td>9</td>
<td>67</td>
<td>603</td>
</tr>
<tr>
<td>camera</td>
<td>4</td>
<td>38</td>
<td>152</td>
</tr>
<tr>
<td>attack</td>
<td>6</td>
<td>12</td>
<td>72</td>
</tr>
<tr>
<td>per</td>
<td>9</td>
<td>39</td>
<td>351</td>
</tr>
</table>
</div>
<div class="total">
<p>Montant Total: 6218</p>
</div>
<div class="footer">
<p>Merci pour votre achat!</p>
</div>
</div>
</body>
</html>

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facture cf36d58b-4737-4190-96da-1dac72ff5d2a</title>
<style>
body { font-family: Arial, sans-serif; }
.invoice { width: 80%; margin: auto; border: 1px solid #ddd; padding: 20px; }
.header, .footer { text-align: center; }
.customer-info, .items { margin-bottom: 20px; }
.items table { width: 100%; border-collapse: collapse; }
.items table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.total { text-align: right; font-weight: bold; }
</style>
</head>
<body>
<div class="invoice">
<div class="header">
<h1>Facture cf36d58b-4737-4190-96da-1dac72ff5d2a</h1>
<p>Date: 2020-01-21</p>
</div>
<div class="customer-info">
<h2>Informations Client</h2>
<p>Nom: Allison Hill</p>
<p>Email: donaldgarcia@example.net</p>
<p>Adresse: 600 Jeffery Parkways
New Jamesside, MT 29394</p>
</div>
<div class="items">
<h2>Articles</h2>
<table>
<tr>
<th>Nom de l'article</th>
<th>Quantité</th>
<th>Prix unitaire</th>
<th>Total</th>
</tr>
<tr>
<td>grow</td>
<td>5</td>
<td>29</td>
<td>145</td>
</tr>
<tr>
<td>dinner</td>
<td>6</td>
<td>23</td>
<td>138</td>
</tr>
<tr>
<td>best</td>
<td>7</td>
<td>22</td>
<td>154</td>
</tr>
<tr>
<td>her</td>
<td>6</td>
<td>87</td>
<td>522</td>
</tr>
</table>
</div>
<div class="total">
<p>Montant Total: 2715</p>
</div>
<div class="footer">
<p>Merci pour votre achat!</p>
</div>
</div>
</body>
</html>

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facture cac5b68c-28f4-4481-a0a0-4dc427209bdf</title>
<style>
body { font-family: Arial, sans-serif; }
.invoice { width: 80%; margin: auto; border: 1px solid #ddd; padding: 20px; }
.header, .footer { text-align: center; }
.customer-info, .items { margin-bottom: 20px; }
.items table { width: 100%; border-collapse: collapse; }
.items table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.total { text-align: right; font-weight: bold; }
</style>
</head>
<body>
<div class="invoice">
<div class="header">
<h1>Facture cac5b68c-28f4-4481-a0a0-4dc427209bdf</h1>
<p>Date: 2023-08-04</p>
</div>
<div class="customer-info">
<h2>Informations Client</h2>
<p>Nom: Austin Gentry</p>
<p>Email: jason76@example.net</p>
<p>Adresse: 38849 Hurst Locks Suite 328
Daviston, VI 14872</p>
</div>
<div class="items">
<h2>Articles</h2>
<table>
<tr>
<th>Nom de l'article</th>
<th>Quantité</th>
<th>Prix unitaire</th>
<th>Total</th>
</tr>
<tr>
<td>image</td>
<td>7</td>
<td>86</td>
<td>602</td>
</tr>
</table>
</div>
<div class="total">
<p>Montant Total: 9871</p>
</div>
<div class="footer">
<p>Merci pour votre achat!</p>
</div>
</div>
</body>
</html>

@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facture 4458a885-ab90-49a4-b5a2-40ae5af30553</title>
<style>
body { font-family: Arial, sans-serif; }
.invoice { width: 80%; margin: auto; border: 1px solid #ddd; padding: 20px; }
.header, .footer { text-align: center; }
.customer-info, .items { margin-bottom: 20px; }
.items table { width: 100%; border-collapse: collapse; }
.items table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.total { text-align: right; font-weight: bold; }
</style>
</head>
<body>
<div class="invoice">
<div class="header">
<h1>Facture 4458a885-ab90-49a4-b5a2-40ae5af30553</h1>
<p>Date: 2020-08-09</p>
</div>
<div class="customer-info">
<h2>Informations Client</h2>
<p>Nom: Andrew Stevens</p>
<p>Email: dudleynicholas@example.net</p>
<p>Adresse: 310 Kendra Common Apt. 164
Reidstad, GA 49021</p>
</div>
<div class="items">
<h2>Articles</h2>
<table>
<tr>
<th>Nom de l'article</th>
<th>Quantité</th>
<th>Prix unitaire</th>
<th>Total</th>
</tr>
<tr>
<td>shoulder</td>
<td>4</td>
<td>30</td>
<td>120</td>
</tr>
<tr>
<td>maintain</td>
<td>7</td>
<td>44</td>
<td>308</td>
</tr>
<tr>
<td>wish</td>
<td>9</td>
<td>38</td>
<td>342</td>
</tr>
<tr>
<td>reveal</td>
<td>6</td>
<td>17</td>
<td>102</td>
</tr>
<tr>
<td>drop</td>
<td>1</td>
<td>50</td>
<td>50</td>
</tr>
</table>
</div>
<div class="total">
<p>Montant Total: 2903</p>
</div>
<div class="footer">
<p>Merci pour votre achat!</p>
</div>
</div>
</body>
</html>

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Facture 87c5421e-ec24-43c5-8754-108ff4188f3f</title>
<style>
body { font-family: Arial, sans-serif; }
.invoice { width: 80%; margin: auto; border: 1px solid #ddd; padding: 20px; }
.header, .footer { text-align: center; }
.customer-info, .items { margin-bottom: 20px; }
.items table { width: 100%; border-collapse: collapse; }
.items table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.total { text-align: right; font-weight: bold; }
</style>
</head>
<body>
<div class="invoice">
<div class="header">
<h1>Facture 87c5421e-ec24-43c5-8754-108ff4188f3f</h1>
<p>Date: 2020-01-02</p>
</div>
<div class="customer-info">
<h2>Informations Client</h2>
<p>Nom: Kendra Maddox DVM</p>
<p>Email: frazierdanny@example.net</p>
<p>Adresse: 46270 Stanton Track Apt. 814
East Nathaniel, GA 71198</p>
</div>
<div class="items">
<h2>Articles</h2>
<table>
<tr>
<th>Nom de l'article</th>
<th>Quantité</th>
<th>Prix unitaire</th>
<th>Total</th>
</tr>
<tr>
<td>middle</td>
<td>1</td>
<td>24</td>
<td>24</td>
</tr>
<tr>
<td>woman</td>
<td>6</td>
<td>49</td>
<td>294</td>
</tr>
<tr>
<td>education</td>
<td>1</td>
<td>40</td>
<td>40</td>
</tr>
</table>
</div>
<div class="total">
<p>Montant Total: 9913</p>
</div>
<div class="footer">
<p>Merci pour votre achat!</p>
</div>
</div>
</body>
</html>

@ -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

@ -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
}
]
Loading…
Cancel
Save