mirror of
https://github.com/Ladebeze66/odoo_toolkit.git
synced 2025-12-15 19:26:55 +01:00
J6-4
This commit is contained in:
parent
d4416f43c3
commit
9bd43e24b1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
/odtkit
|
/odtkit
|
||||||
/exported_tickets
|
|
||||||
config.py
|
config.py
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,38 +0,0 @@
|
|||||||
import re
|
|
||||||
import html
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
def clean_html(content):
|
|
||||||
"""Nettoie le contenu HTML en supprimant les balises."""
|
|
||||||
if not content:
|
|
||||||
return ""
|
|
||||||
soup = BeautifulSoup(content, 'html.parser')
|
|
||||||
return soup.get_text(separator='\n', strip=True)
|
|
||||||
|
|
||||||
def filter_ticket_data(ticket_data):
|
|
||||||
"""Filtre les données d'un ticket pour ne garder que les informations essentielles."""
|
|
||||||
|
|
||||||
# Vérifier que ticket_data est bien une liste et extraire le premier élément
|
|
||||||
if isinstance(ticket_data, list) and len(ticket_data) > 0:
|
|
||||||
ticket_data = ticket_data[0]
|
|
||||||
else:
|
|
||||||
return {"Erreur": "Format de ticket invalide"}
|
|
||||||
|
|
||||||
filtered_ticket = {
|
|
||||||
"ID du Ticket": ticket_data.get("id", "ID non disponible"),
|
|
||||||
"Nom": ticket_data.get("name", "Nom inconnu"),
|
|
||||||
"Code": ticket_data.get("code", "N/A"),
|
|
||||||
"Date Limite": ticket_data.get("date_deadline", "Non définie"),
|
|
||||||
"Projet": {
|
|
||||||
"ID": ticket_data.get("project_id", [None, "Projet inconnu"])[0],
|
|
||||||
"Nom": ticket_data.get("project_id", [None, "Projet inconnu"])[1]
|
|
||||||
},
|
|
||||||
"Étape": {
|
|
||||||
"ID": ticket_data.get("stage_id", [None, "Étape inconnue"])[0],
|
|
||||||
"Nom": ticket_data.get("stage_id", [None, "Étape inconnue"])[1]
|
|
||||||
},
|
|
||||||
"Description": clean_html(ticket_data.get("description", "")),
|
|
||||||
"Discussions": ticket_data.get("message_ids", [])
|
|
||||||
}
|
|
||||||
|
|
||||||
return filtered_ticket
|
|
||||||
File diff suppressed because one or more lines are too long
@ -1,3 +0,0 @@
|
|||||||
[
|
|
||||||
10157
|
|
||||||
]
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
from ticket_manager import TicketManager
|
from ticket_manager import TicketManager
|
||||||
from utils import get_user_choice, print_error
|
from utils import print_error
|
||||||
|
|
||||||
# Initialisation de l'objet
|
# Initialisation de l'objet
|
||||||
ticket_manager = TicketManager()
|
ticket_manager = TicketManager()
|
||||||
|
|||||||
@ -1,66 +0,0 @@
|
|||||||
def handle_list_models():
|
|
||||||
"""Gère l'affichage de la liste des modèles"""
|
|
||||||
ticket_manager.list_models()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_list_model_fields():
|
|
||||||
"""Gère l'affichage des champs d'un modèle"""
|
|
||||||
model_name = input("\nEntrez le nom du modèle: ")
|
|
||||||
if not model_name:
|
|
||||||
print("Aucun nom de modèle fourni.")
|
|
||||||
return
|
|
||||||
ticket_manager.list_model_fields(model_name)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_export_model_fields_to_json():
|
|
||||||
"""Gère l'exportation des informations des champs d'un modèle en JSON"""
|
|
||||||
model_name = input("\nEntrez le nom du modèle: ")
|
|
||||||
if not model_name:
|
|
||||||
print("Aucun nom de modèle fourni.")
|
|
||||||
return
|
|
||||||
filename = input("Entrez le nom du fichier pour l'exportation: ")
|
|
||||||
if not filename:
|
|
||||||
print("Aucun nom de fichier fourni.")
|
|
||||||
return
|
|
||||||
ticket_manager.export_model_fields_to_json(model_name, filename)
|
|
||||||
|
|
||||||
///partie ticket_manager.py
|
|
||||||
def list_models(self):
|
|
||||||
"""Affiche la liste des modèles disponibles dans Odoo"""
|
|
||||||
models = self._safe_execute('ir.model', 'search_read', [], ['model', 'name'])
|
|
||||||
if not models:
|
|
||||||
print_error("Aucun modèle disponible.")
|
|
||||||
return []
|
|
||||||
|
|
||||||
print("\nListe des modèles disponibles:")
|
|
||||||
for model in models:
|
|
||||||
print(f"Modèle: {model['name']} (ID: {model['model']})")
|
|
||||||
return models
|
|
||||||
|
|
||||||
def list_model_fields(self, model_name):
|
|
||||||
"""Affiche les champs d'un modèle donné"""
|
|
||||||
fields_info = self._safe_execute(model_name, 'fields_get')
|
|
||||||
if not fields_info:
|
|
||||||
print_error(f"Aucun champ trouvé pour le modèle {model_name}.")
|
|
||||||
return []
|
|
||||||
|
|
||||||
print(f"\nChamps du modèle {model_name}:")
|
|
||||||
for field_name, field_data in fields_info.items():
|
|
||||||
print(f"Champ: {field_name} - Type: {field_data['type']}")
|
|
||||||
return fields_info
|
|
||||||
|
|
||||||
def export_model_fields_to_json(self, model_name, filename):
|
|
||||||
"""Exporte les champs d'un modèle dans un fichier JSON"""
|
|
||||||
fields_info = self._safe_execute(model_name, 'fields_get')
|
|
||||||
if not fields_info:
|
|
||||||
print_error(f"Aucun champ trouvé pour le modèle {model_name}.")
|
|
||||||
return
|
|
||||||
|
|
||||||
data = {field_name: field_data['type'] for field_name, field_data in fields_info.items()}
|
|
||||||
filepath = os.path.join(EXPORT_DIR, filename)
|
|
||||||
|
|
||||||
if save_json(filepath, data):
|
|
||||||
print(f"Champs du modèle {model_name} exportés dans {filepath}")
|
|
||||||
else:
|
|
||||||
print_error(f"Erreur lors de l'exportation des champs du modèle {model_name} dans {filepath}")
|
|
||||||
@ -1,11 +1,8 @@
|
|||||||
from odoo_connection import OdooConnection
|
from odoo_connection import OdooConnection
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import re
|
from utils import print_error
|
||||||
from utils import save_json, ensure_export_directory, print_error
|
|
||||||
from config import EXPORT_DIR
|
from config import EXPORT_DIR
|
||||||
from data_filter import filter_ticket_data
|
|
||||||
import odoorpc
|
|
||||||
|
|
||||||
class TicketManager:
|
class TicketManager:
|
||||||
"""Gestionnaire de tickets simplifié avec seulement les fonctionnalités essentielles"""
|
"""Gestionnaire de tickets simplifié avec seulement les fonctionnalités essentielles"""
|
||||||
@ -151,7 +148,7 @@ class TicketManager:
|
|||||||
|
|
||||||
# Récupérer les tickets du projet
|
# Récupérer les tickets du projet
|
||||||
domain = [('project_id', '=', project_id)]
|
domain = [('project_id', '=', project_id)]
|
||||||
ticket_ids = self._safe_execute(self.model_name, 'search', domain, 0, 1000)
|
ticket_ids = self._safe_execute(self.model_name, 'search', domain, 0, 10)
|
||||||
if not ticket_ids:
|
if not ticket_ids:
|
||||||
print_error(f"Aucun ticket trouvé pour le projet {project_id}.")
|
print_error(f"Aucun ticket trouvé pour le projet {project_id}.")
|
||||||
return
|
return
|
||||||
|
|||||||
39
utils.py
39
utils.py
@ -1,41 +1,2 @@
|
|||||||
import os
|
|
||||||
import json
|
|
||||||
from config import EXPORT_DIR
|
|
||||||
|
|
||||||
def ensure_export_directory(subdir=None):
|
|
||||||
"""Assure que le répertoire d'export existe"""
|
|
||||||
if subdir:
|
|
||||||
directory = os.path.join(EXPORT_DIR, subdir)
|
|
||||||
else:
|
|
||||||
directory = EXPORT_DIR
|
|
||||||
os.makedirs(directory, exist_ok=True)
|
|
||||||
return directory
|
|
||||||
|
|
||||||
def save_json(filename, data):
|
|
||||||
"""Sauvegarde des données au format JSON"""
|
|
||||||
try:
|
|
||||||
with open(filename, 'w', encoding='utf-8') as f:
|
|
||||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Erreur lors de la sauvegarde du fichier {filename}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_user_choice(prompt, options):
|
|
||||||
"""Obtient un choix utilisateur parmi une liste d'options"""
|
|
||||||
while True:
|
|
||||||
print(prompt)
|
|
||||||
for i, option in enumerate(options, 1):
|
|
||||||
print(f"{i}. {option}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
choice = int(input("Votre choix: "))
|
|
||||||
if 1 <= choice <= len(options):
|
|
||||||
return choice
|
|
||||||
else:
|
|
||||||
print("Choix invalide. Veuillez réessayer.")
|
|
||||||
except ValueError:
|
|
||||||
print("Veuillez entrer un nombre valide.")
|
|
||||||
|
|
||||||
def print_error(message):
|
def print_error(message):
|
||||||
print(f" Erreur: {message}")
|
print(f" Erreur: {message}")
|
||||||
Loading…
x
Reference in New Issue
Block a user