mirror of
https://github.com/Ladebeze66/odoo_toolkit.git
synced 2025-12-13 09:06:52 +01:00
182 lines
7.2 KiB
Python
182 lines
7.2 KiB
Python
import os
|
|
import json
|
|
from datetime import datetime
|
|
from utils import print_success, print_error, EXPORT_DIR, prompt_yes_no, INTERACTIVE, print_info
|
|
from ticket_manager import TicketManager
|
|
from data_filter import run_filter_wizard
|
|
|
|
# Initialisation de l'objet
|
|
ticket_manager = TicketManager()
|
|
|
|
def handle_list_models():
|
|
"""Affiche et sauvegarde la liste des modèles disponibles"""
|
|
models = ticket_manager.get_all_models()
|
|
if models:
|
|
print("\n Modèles disponibles:")
|
|
for model, name in models.items():
|
|
print(f"- {model} : {name}")
|
|
|
|
def handle_list_model_fields():
|
|
"""Demande à l'utilisateur un modèle et affiche ses champs avec leur type."""
|
|
model_name = input("\nEntrez le nom du modèle à inspecter (ou 'q' pour quitter): ")
|
|
if model_name.lower() == 'q':
|
|
return
|
|
|
|
# Assurons-nous que model_name est bien une chaîne de caractères
|
|
model_name = str(model_name)
|
|
|
|
fields = ticket_manager.get_model_fields_with_types(model_name)
|
|
if fields:
|
|
print(f"\nChamps du modèle '{model_name}':")
|
|
for field, info in fields.items():
|
|
relation_info = f" (relation avec {info['relation']})" if info["relation"] else ""
|
|
required_info = " [Obligatoire]" if info.get("required") else ""
|
|
readonly_info = " [Lecture seule]" if info.get("readonly") else ""
|
|
|
|
print(f"- {field} : {info['type']}{relation_info}{required_info}{readonly_info}")
|
|
|
|
# Afficher la description du champ si disponible
|
|
if info.get("string") and info.get("string") != field:
|
|
print(f" Label: {info['string']}")
|
|
|
|
# Afficher l'aide si disponible
|
|
if info.get("help"):
|
|
print(f" Description: {info['help']}")
|
|
|
|
# Afficher les options si c'est un champ de sélection
|
|
if info.get("selection"):
|
|
print(" Options:")
|
|
for key, value in info["selection"]:
|
|
print(f" - {key}: {value}")
|
|
|
|
print("") # Ligne vide pour séparer les champs
|
|
|
|
def handle_search_ticket_by_id():
|
|
"""Gère la recherche d'un ticket par ID"""
|
|
ticket_id_input = input("Entrez l'ID du ticket(ou 'q' pour quitter): ")
|
|
if ticket_id_input.lower() == 'q':
|
|
return
|
|
try:
|
|
ticket_id = int(ticket_id_input)
|
|
except ValueError:
|
|
print_error("L'ID du ticket doit être un n ombre entier.")
|
|
return
|
|
|
|
ticket = ticket_manager.get_ticket_by_id(ticket_id)
|
|
if ticket:
|
|
print("\n Ticket trouvé:")
|
|
print(ticket)
|
|
else:
|
|
print_error(f"Aucun ticket trouvé avec l'ID: {ticket_id}")
|
|
|
|
def handle_search_ticket_by_code():
|
|
"""Recherche un ticket via son code"""
|
|
ticket_code = input("\nEntrez le code du ticket à rechercher (ou 'q' pour quitter): ")
|
|
if ticket_code.lower() == 'q':
|
|
return
|
|
|
|
ticket = ticket_manager.get_ticket_by_code(ticket_code)
|
|
if ticket:
|
|
print("\n Ticket trouvé:")
|
|
print(ticket)
|
|
else:
|
|
print_error(f"Aucun ticket trouvé avec le code '{ticket_code}'.")
|
|
|
|
def handle_project_tickets_by_stage():
|
|
"""Gère l'exportation des tickets d'un projet par étape"""
|
|
# Récupérer la liste des projets disponibles
|
|
projects = ticket_manager.get_available_projects()
|
|
if not projects:
|
|
print("Aucun projet disponible. Impossible de continuer.")
|
|
return
|
|
|
|
# Afficher les projets disponibles pour aider l'utilisateur
|
|
print("\nProjets disponibles:")
|
|
for proj_id, proj_name in projects.items():
|
|
print(f"- ID: {proj_id} - Nom: {proj_name}")
|
|
|
|
# Demander à l'utilisateur de choisir un projet
|
|
project_id_input = input("\nEntrez l'ID du projet (ou 'q' pour quitter, 0 pour tous): ")
|
|
if project_id_input.lower() == 'q':
|
|
return
|
|
|
|
project_id = None
|
|
if project_id_input != '0':
|
|
try:
|
|
project_id = int(project_id_input)
|
|
if project_id not in projects.keys():
|
|
print_error(f"Aucun projet trouvé avec l'ID: {project_id}")
|
|
return
|
|
except ValueError:
|
|
print("L'ID du projet doit être un nombre entier.")
|
|
return
|
|
|
|
# Demander à l'utilisateur s'il souhaite filtrer par étape également
|
|
filter_by_stage = input("\nSouhaitez-vous filtrer par étape aussi? (o/n): ").lower() == 'o'
|
|
|
|
stage_id = None
|
|
if filter_by_stage:
|
|
# Récupérer et afficher les étapes disponibles
|
|
stages = ticket_manager._safe_execute('project.task.type', 'search_read', [], ['id', 'name'])
|
|
if stages:
|
|
print("\nÉtapes disponibles:")
|
|
for stage in stages:
|
|
print(f"- ID: {stage['id']} - Nom: {stage['name']}")
|
|
|
|
stage_id_input = input("\nEntrez l'ID de l'étape (ou 'q' pour quitter, 0 pour toutes): ")
|
|
if stage_id_input.lower() == 'q':
|
|
return
|
|
|
|
if stage_id_input != '0':
|
|
try:
|
|
stage_id = int(stage_id_input)
|
|
# Vérifier que l'étape existe
|
|
stage_exists = any(stage['id'] == stage_id for stage in stages)
|
|
if not stage_exists:
|
|
print_error(f"Aucune étape trouvée avec l'ID: {stage_id}")
|
|
return
|
|
except ValueError:
|
|
print("L'ID de l'étape doit être un nombre entier.")
|
|
return
|
|
|
|
# Exporter les tickets selon les filtres choisis
|
|
ticket_manager.export_tickets_by_project_and_stage(project_id, stage_id)
|
|
|
|
def handle_extract_ticket_attachments():
|
|
"""Gère l'extraction des pièces jointes et messages d'un ticket"""
|
|
# Demander à l'utilisateur d'entrer l'ID du ticket
|
|
ticket_id_input = input("\nEntrez l'ID du ticket à extraire (ou 'q' pour quitter): ")
|
|
if ticket_id_input.lower() == 'q':
|
|
return
|
|
|
|
try:
|
|
ticket_id = int(ticket_id_input)
|
|
except ValueError:
|
|
print_error("L'ID du ticket doit être un nombre entier.")
|
|
return
|
|
|
|
# Extraire les pièces jointes et les messages
|
|
output_dir = ticket_manager.extract_ticket_attachments_and_messages(ticket_id)
|
|
|
|
if output_dir:
|
|
print(f"\nExtraction terminée avec succès. Les fichiers ont été enregistrés dans: {output_dir}")
|
|
else:
|
|
print_error(f"L'extraction a échoué pour le ticket avec l'ID {ticket_id}")
|
|
|
|
def handle_filter_html_messages():
|
|
"""Gère le filtrage des messages HTML dans les tickets exportés"""
|
|
print("\n==== FILTRAGE DES MESSAGES HTML ====")
|
|
|
|
if not os.path.exists(EXPORT_DIR) or not os.listdir(EXPORT_DIR):
|
|
print_error(f"Aucun ticket exporté trouvé dans {EXPORT_DIR}. Veuillez d'abord exporter des tickets.")
|
|
return
|
|
|
|
print_info("Cette fonctionnalité va analyser les tickets exportés et nettoyer les messages HTML.")
|
|
print_info("Les messages nettoyés seront sauvegardés dans un nouveau répertoire 'filtered_tickets'.")
|
|
|
|
if INTERACTIVE and not prompt_yes_no("Voulez-vous continuer?"):
|
|
print_info("Opération annulée.")
|
|
return
|
|
|
|
# Exécuter l'assistant de filtrage
|
|
run_filter_wizard() |