llm_ticket3/track.py

72 lines
2.2 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# extract_tracking_values.py
import json
import os
from odoo.auth_manager import AuthManager
from odoo.ticket_manager import TicketManager
from odoo.message_manager import MessageManager
CONFIG_FILE = "config.json"
def load_config(path=CONFIG_FILE):
with open(path, "r") as f:
return json.load(f)
def extract_tracking_values(ticket_code: str, config_file: str = CONFIG_FILE):
config = load_config(config_file)
odoo = config["odoo"]
# Auth
auth = AuthManager(
url=odoo["url"],
db=odoo["db"],
username=odoo["username"],
api_key=odoo["api_key"]
)
if not auth.login():
print("❌ Authentification échouée.")
return
# Get ticket
ticket_manager = TicketManager(auth)
ticket = ticket_manager.get_ticket_by_code(ticket_code)
if not ticket or "id" not in ticket:
print(f"❌ Ticket non trouvé : {ticket_code}")
return
ticket_id = ticket["id"]
# Get messages
msg_manager = MessageManager(auth)
messages = msg_manager.get_ticket_messages(ticket_id)
# Collect tracking IDs
tracking_ids = []
for msg in messages:
tracking_ids.extend(msg.get("tracking_value_ids", []))
if not tracking_ids:
print(f" Aucun changement détecté pour le ticket {ticket_code}")
return
# Fetch tracking values
tracking_data = auth.read(
model="mail.tracking.value",
ids=tracking_ids,
fields=["field", "field_desc", "old_value_char", "new_value_char"]
)
# Export JSON
output_path = os.path.join("output", f"tracking_values_{ticket_code}.json")
os.makedirs("output", exist_ok=True)
with open(output_path, "w", encoding="utf-8") as f:
json.dump(tracking_data, f, indent=2, ensure_ascii=False)
print(f"✅ Modifications sauvegardées dans : {output_path}")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Extract tracking changes for an Odoo ticket.")
parser.add_argument("ticket_code", help="Code du ticket Odoo (ex: T12345)")
parser.add_argument("--config", "-c", help="Fichier config", default=CONFIG_FILE)
args = parser.parse_args()
extract_tracking_values(args.ticket_code, args.config)