#!/usr/bin/env python3 """ Script de génération de données de démonstration pour Covoit'Ouest Génère des données réalistes pour tous les modules Odoo """ import xmlrpc.client from datetime import datetime, timedelta import random # Configuration url = 'http://localhost:8069' db = 'covoiturage_db' username = 'admin' password = 'admin' # Connexion à Odoo print("🔌 Connexion à Odoo...") common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url)) uid = common.authenticate(db, username, password, {}) if not uid: print("❌ Erreur: Impossible de se connecter à Odoo") exit(1) print(f"✅ Connecté en tant qu'utilisateur ID: {uid}\n") models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) # Données de référence CONDUCTEURS = [ {'name': 'Jean Dupont', 'email': 'jean.dupont@email.fr', 'phone': '+33 6 12 34 56 78', 'city': 'La Rochelle'}, {'name': 'Pierre Martin', 'email': 'pierre.martin@email.fr', 'phone': '+33 6 23 45 67 89', 'city': 'Nantes'}, {'name': 'Sophie Bernard', 'email': 'sophie.bernard@email.fr', 'phone': '+33 6 34 56 78 90', 'city': 'Bordeaux'}, {'name': 'Luc Petit', 'email': 'luc.petit@email.fr', 'phone': '+33 6 45 67 89 01', 'city': 'La Rochelle'}, {'name': 'Emma Dubois', 'email': 'emma.dubois@email.fr', 'phone': '+33 6 56 78 90 12', 'city': 'Nantes'}, {'name': 'Thomas Robert', 'email': 'thomas.robert@email.fr', 'phone': '+33 6 67 89 01 23', 'city': 'Poitiers'}, {'name': 'Julie Moreau', 'email': 'julie.moreau@email.fr', 'phone': '+33 6 78 90 12 34', 'city': 'Angoulême'}, {'name': 'Nicolas Simon', 'email': 'nicolas.simon@email.fr', 'phone': '+33 6 89 01 23 45', 'city': 'Bordeaux'}, ] PASSAGERS = [ {'name': 'Marie Martin', 'email': 'marie.martin@email.fr', 'phone': '+33 6 98 76 54 32', 'city': 'La Rochelle'}, {'name': 'Antoine Leroy', 'email': 'antoine.leroy@email.fr', 'phone': '+33 6 87 65 43 21', 'city': 'Nantes'}, {'name': 'Camille Girard', 'email': 'camille.girard@email.fr', 'phone': '+33 6 76 54 32 10', 'city': 'Bordeaux'}, {'name': 'Lucas Blanc', 'email': 'lucas.blanc@email.fr', 'phone': '+33 6 65 43 21 09', 'city': 'La Rochelle'}, {'name': 'Léa Garnier', 'email': 'lea.garnier@email.fr', 'phone': '+33 6 54 32 10 98', 'city': 'Nantes'}, {'name': 'Hugo Faure', 'email': 'hugo.faure@email.fr', 'phone': '+33 6 43 21 09 87', 'city': 'Poitiers'}, {'name': 'Chloé André', 'email': 'chloe.andre@email.fr', 'phone': '+33 6 32 10 98 76', 'city': 'Angoulême'}, {'name': 'Maxime Mercier', 'email': 'maxime.mercier@email.fr', 'phone': '+33 6 21 09 87 65', 'city': 'Bordeaux'}, {'name': 'Laura Lefebvre', 'email': 'laura.lefebvre@email.fr', 'phone': '+33 6 10 98 76 54', 'city': 'La Rochelle'}, {'name': 'Alexandre Lambert', 'email': 'alexandre.lambert@email.fr', 'phone': '+33 6 09 87 65 43', 'city': 'Nantes'}, ] TRAJETS = [ {'name': 'La Rochelle → Nantes', 'price': 15.00, 'distance': '125 km', 'duration': '1h30'}, {'name': 'Nantes → Bordeaux', 'price': 25.00, 'distance': '310 km', 'duration': '3h00'}, {'name': 'Bordeaux → La Rochelle', 'price': 20.00, 'distance': '195 km', 'duration': '2h00'}, {'name': 'La Rochelle → Poitiers', 'price': 18.00, 'distance': '145 km', 'duration': '1h45'}, {'name': 'Poitiers → Nantes', 'price': 22.00, 'distance': '210 km', 'duration': '2h15'}, {'name': 'Angoulême → Bordeaux', 'price': 12.00, 'distance': '115 km', 'duration': '1h15'}, {'name': 'Nantes → La Rochelle', 'price': 15.00, 'distance': '125 km', 'duration': '1h30'}, ] print("="*60) print("GÉNÉRATION DE DONNÉES DE DÉMONSTRATION COVOIT'OUEST") print("="*60) # Créer les conducteurs print("\n📍 Création des conducteurs...") conducteur_ids = [] for conducteur in CONDUCTEURS: existing = models.execute_kw(db, uid, password, 'res.partner', 'search', [[('email', '=', conducteur['email'])]]) if existing: conducteur_ids.append(existing[0]) print(f" ✓ {conducteur['name']} (déjà existant)") else: cid = models.execute_kw(db, uid, password, 'res.partner', 'create', [{ 'name': conducteur['name'], 'email': conducteur['email'], 'phone': conducteur['phone'], 'city': conducteur['city'], 'country_id': 75, # France 'is_company': False, 'comment': 'Conducteur Covoit\'Ouest', }]) conducteur_ids.append(cid) print(f" ✓ {conducteur['name']} créé (ID: {cid})") # Créer les passagers print("\n👥 Création des passagers...") passager_ids = [] for passager in PASSAGERS: existing = models.execute_kw(db, uid, password, 'res.partner', 'search', [[('email', '=', passager['email'])]]) if existing: passager_ids.append(existing[0]) print(f" ✓ {passager['name']} (déjà existant)") else: pid = models.execute_kw(db, uid, password, 'res.partner', 'create', [{ 'name': passager['name'], 'email': passager['email'], 'phone': passager['phone'], 'city': passager['city'], 'country_id': 75, # France 'is_company': False, 'comment': 'Passager Covoit\'Ouest', }]) passager_ids.append(pid) print(f" ✓ {passager['name']} créé (ID: {pid})") # Créer la catégorie Trajets print("\n🗂️ Création de la catégorie Trajets...") categ_ids = models.execute_kw(db, uid, password, 'product.category', 'search', [[('name', '=', 'Trajets')]]) if categ_ids: categ_id = categ_ids[0] print(f" ✓ Catégorie Trajets (déjà existante)") else: categ_id = models.execute_kw(db, uid, password, 'product.category', 'create', [{ 'name': 'Trajets', }]) print(f" ✓ Catégorie Trajets créée (ID: {categ_id})") # Créer les trajets print("\n🚗 Création des trajets...") trajet_ids = [] for trajet in TRAJETS: existing = models.execute_kw(db, uid, password, 'product.template', 'search', [[('name', '=', trajet['name'])]]) if existing: product_template_id = existing[0] print(f" ✓ {trajet['name']} (déjà existant)") else: product_template_id = models.execute_kw(db, uid, password, 'product.template', 'create', [{ 'name': trajet['name'], 'type': 'service', 'categ_id': categ_id, 'list_price': trajet['price'], 'standard_price': trajet['price'] * 0.2, # 20% commission 'description_sale': f"Trajet en covoiturage {trajet['name']}\nDurée: {trajet['duration']}\nDistance: {trajet['distance']}", 'sale_ok': True, 'purchase_ok': False, }]) print(f" ✓ {trajet['name']} créé - {trajet['price']}€ (ID: {product_template_id})") # Récupérer le product.product product_id = models.execute_kw(db, uid, password, 'product.product', 'search', [[('product_tmpl_id', '=', product_template_id)]])[0] trajet_ids.append(product_id) # Créer des réservations (commandes) print("\n📝 Création des réservations...") nb_reservations = 30 for i in range(nb_reservations): # Date aléatoire dans les 3 derniers mois days_ago = random.randint(1, 90) order_date = datetime.now() - timedelta(days=days_ago) # Passager et trajet aléatoires passager_id = random.choice(passager_ids) product_id = random.choice(trajet_ids) # 80% de chance d'être confirmée state = 'sale' if random.random() < 0.8 else 'draft' try: # Créer la commande order_id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{ 'partner_id': passager_id, 'date_order': order_date.strftime('%Y-%m-%d %H:%M:%S'), 'state': 'draft', }]) # Ajouter la ligne de commande models.execute_kw(db, uid, password, 'sale.order.line', 'create', [{ 'order_id': order_id, 'product_id': product_id, 'product_uom_qty': 1, }]) # Confirmer si nécessaire if state == 'sale': models.execute_kw(db, uid, password, 'sale.order', 'action_confirm', [[order_id]]) order_info = models.execute_kw(db, uid, password, 'sale.order', 'read', [[order_id]], {'fields': ['name', 'state', 'amount_total']}) status = "✅" if state == 'sale' else "📋" print(f" {status} Commande {order_info[0]['name']} - {order_info[0]['amount_total']}€ ({order_info[0]['state']})") except Exception as e: print(f" ⚠️ Erreur lors de la création de la commande {i+1}: {str(e)[:80]}") # Créer des leads CRM print("\n🎯 Création des leads CRM...") PROSPECTS = [ {'name': 'Nouveau conducteur - Marc Dubois', 'email': 'marc.dubois@email.fr', 'city': 'Nantes'}, {'name': 'Conductrice potentielle - Anne Rousseau', 'email': 'anne.rousseau@email.fr', 'city': 'Bordeaux'}, {'name': 'Partenariat entreprise - TechCorp', 'email': 'contact@techcorp.fr', 'city': 'La Rochelle'}, {'name': 'Lead conducteur - Paul Vincent', 'email': 'paul.vincent@email.fr', 'city': 'Poitiers'}, {'name': 'Prospect B2B - StartupCo', 'email': 'info@startupco.fr', 'city': 'Nantes'}, ] for prospect in PROSPECTS: existing = models.execute_kw(db, uid, password, 'crm.lead', 'search', [[('email_from', '=', prospect['email'])]]) if existing: print(f" ✓ {prospect['name']} (déjà existant)") else: # État aléatoire stages = models.execute_kw(db, uid, password, 'crm.stage', 'search_read', [[]], {'fields': ['id', 'name'], 'limit': 5}) stage_id = random.choice(stages)['id'] if stages else False lead_id = models.execute_kw(db, uid, password, 'crm.lead', 'create', [{ 'name': prospect['name'], 'type': 'lead', 'email_from': prospect['email'], 'city': prospect['city'], 'country_id': 75, 'stage_id': stage_id, 'user_id': uid, 'description': f'Prospect intéressé par Covoit\'Ouest - {prospect["city"]}', }]) print(f" ✓ {prospect['name']} créé (ID: {lead_id})") # Statistiques finales print("\n" + "="*60) print("📊 STATISTIQUES FINALES") print("="*60) # Compter les contacts nb_contacts = models.execute_kw(db, uid, password, 'res.partner', 'search_count', [[]]) print(f"👥 Contacts: {nb_contacts}") # Compter les produits (trajets) nb_produits = models.execute_kw(db, uid, password, 'product.template', 'search_count', [[('categ_id', '=', categ_id)]]) print(f"🚗 Trajets: {nb_produits}") # Compter les commandes nb_commandes = models.execute_kw(db, uid, password, 'sale.order', 'search_count', [[]]) nb_confirmees = models.execute_kw(db, uid, password, 'sale.order', 'search_count', [[('state', 'in', ['sale', 'done'])]]) print(f"📝 Commandes: {nb_commandes} (dont {nb_confirmees} confirmées)") # Calculer le CA total commandes = models.execute_kw(db, uid, password, 'sale.order', 'search_read', [[('state', 'in', ['sale', 'done'])]], {'fields': ['amount_total']}) ca_total = sum([cmd['amount_total'] for cmd in commandes]) print(f"💰 Chiffre d'affaires: {ca_total:.2f}€") # Compter les leads nb_leads = models.execute_kw(db, uid, password, 'crm.lead', 'search_count', [[]]) print(f"🎯 Leads CRM: {nb_leads}") print("\n" + "="*60) print("✅ GÉNÉRATION DE DONNÉES TERMINÉE AVEC SUCCÈS!") print("="*60) print("\n🌐 Accédez à Odoo: http://localhost:8069") print(" Base de données: covoiturage_db") print(" Login: admin / admin") print("\n📈 Vous pouvez maintenant créer vos tableaux de bord avec des données réalistes!")