You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
|
1 year ago
|
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'.")
|