mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-16 00:06:53 +01:00
14:59
This commit is contained in:
parent
84b6bdb328
commit
3bf32de480
83
output/ticket_T11067/all_messages.json
Normal file
83
output/ticket_T11067/all_messages.json
Normal file
File diff suppressed because one or more lines are too long
43
output/ticket_T11067/ticket_info.json
Normal file
43
output/ticket_T11067/ticket_info.json
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"id": 11046,
|
||||||
|
"name": "changement nom centrale d'enrobage",
|
||||||
|
"description": "<p><br></p>",
|
||||||
|
"stage_id": [
|
||||||
|
8,
|
||||||
|
"Clôturé"
|
||||||
|
],
|
||||||
|
"project_id": [
|
||||||
|
3,
|
||||||
|
"Demandes"
|
||||||
|
],
|
||||||
|
"partner_id": [
|
||||||
|
5144,
|
||||||
|
"CONSEIL DEPARTEMENTAL DU MORBIHAN (56), Dominique CARVAL"
|
||||||
|
],
|
||||||
|
"user_id": [
|
||||||
|
32,
|
||||||
|
"Romuald GRUSON"
|
||||||
|
],
|
||||||
|
"date_start": "2025-03-18 13:22:28",
|
||||||
|
"date_end": false,
|
||||||
|
"create_date": "2025-03-18 13:22:27",
|
||||||
|
"write_date": "2025-04-02 07:16:48",
|
||||||
|
"message_ids": [
|
||||||
|
228803,
|
||||||
|
227733,
|
||||||
|
227732,
|
||||||
|
227731,
|
||||||
|
227730,
|
||||||
|
227728,
|
||||||
|
227726,
|
||||||
|
227725,
|
||||||
|
227724
|
||||||
|
],
|
||||||
|
"message_follower_ids": [
|
||||||
|
89590,
|
||||||
|
89592,
|
||||||
|
89593
|
||||||
|
],
|
||||||
|
"timesheet_ids": [],
|
||||||
|
"attachment_ids": []
|
||||||
|
}
|
||||||
@ -79,8 +79,32 @@ def main():
|
|||||||
|
|
||||||
# Récupérer et sauvegarder les pièces jointes
|
# Récupérer et sauvegarder les pièces jointes
|
||||||
attachments = attachment_manager.get_ticket_attachments(ticket_id)
|
attachments = attachment_manager.get_ticket_attachments(ticket_id)
|
||||||
attachments_path = os.path.join(output_dir, "attachments_info.json")
|
attachments_info = []
|
||||||
save_json(attachments, attachments_path)
|
attachment_dir = os.path.join(output_dir, "attachments")
|
||||||
|
os.makedirs(attachment_dir, exist_ok=True)
|
||||||
|
|
||||||
|
for attachment in attachments:
|
||||||
|
file_data = attachment.get("datas")
|
||||||
|
if file_data:
|
||||||
|
file_name = attachment.get("name", "unnamed_file")
|
||||||
|
file_path = os.path.join(attachment_dir, file_name)
|
||||||
|
|
||||||
|
# Sauvegarder le fichier binaire
|
||||||
|
with open(file_path, "wb") as f:
|
||||||
|
f.write(base64.b64decode(file_data))
|
||||||
|
|
||||||
|
# Ajouter l'information de l'attachement à la liste
|
||||||
|
attachments_info.append({
|
||||||
|
"id": attachment.get("id"),
|
||||||
|
"name": file_name,
|
||||||
|
"path": file_path,
|
||||||
|
"mimetype": attachment.get("mimetype"),
|
||||||
|
"create_date": attachment.get("create_date")
|
||||||
|
})
|
||||||
|
|
||||||
|
# Sauvegarder les métadonnées des pièces jointes
|
||||||
|
attachments_info_path = os.path.join(output_dir, "attachments_info.json")
|
||||||
|
save_json(attachments_info, attachments_info_path)
|
||||||
|
|
||||||
# Génération de structure.json
|
# Génération de structure.json
|
||||||
structure = {
|
structure = {
|
||||||
@ -98,7 +122,7 @@ def main():
|
|||||||
print("Extraction terminée avec succès")
|
print("Extraction terminée avec succès")
|
||||||
print(f"- Informations du ticket: {ticket_info_path}")
|
print(f"- Informations du ticket: {ticket_info_path}")
|
||||||
print(f"- Messages: {all_messages_path}")
|
print(f"- Messages: {all_messages_path}")
|
||||||
print(f"- Pièces jointes: {attachments_path}")
|
print(f"- Pièces jointes: {attachments_info_path}")
|
||||||
print(f"- Structure: {structure_path}")
|
print(f"- Structure: {structure_path}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Binary file not shown.
@ -1,15 +1,50 @@
|
|||||||
|
import os
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
from typing import List, Dict, Any
|
from typing import List, Dict, Any
|
||||||
from .auth_manager import AuthManager
|
from datetime import datetime
|
||||||
|
|
||||||
class AttachmentManager:
|
class AttachmentManager:
|
||||||
def __init__(self, auth: AuthManager):
|
def __init__(self, odoo_instance, model_name: str = "project.task"):
|
||||||
self.auth = auth
|
self.odoo = odoo_instance
|
||||||
|
self.model_name = model_name
|
||||||
|
|
||||||
def get_ticket_attachments(self, ticket_id: int) -> List[Dict[str, Any]]:
|
def fetch_attachments(self, ticket_id: int) -> List[Dict[str, Any]]:
|
||||||
params = {
|
attachments = self.odoo.execute('ir.attachment', 'search_read', [
|
||||||
"model": "ir.attachment",
|
[('res_model', '=', self.model_name), ('res_id', '=', ticket_id)]
|
||||||
"method": "search_read",
|
], ['id', 'name', 'datas', 'mimetype', 'create_date', 'description'])
|
||||||
"args": [[[ "res_id", "=", ticket_id], ["res_model", "=", "project.task"]]],
|
|
||||||
"kwargs": {"fields": ["id", "name", "datas"]}
|
return attachments if isinstance(attachments, list) else []
|
||||||
}
|
|
||||||
return self.auth._rpc_call("/web/dataset/call_kw", params)
|
def save_attachments(self, ticket_id: int, ticket_dir: str, attachments: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
||||||
|
attachment_dir = os.path.join(ticket_dir, "attachments")
|
||||||
|
os.makedirs(attachment_dir, exist_ok=True)
|
||||||
|
|
||||||
|
attachment_info_list = []
|
||||||
|
|
||||||
|
for attachment in attachments:
|
||||||
|
if attachment.get("datas"):
|
||||||
|
attachment_name = f"{attachment['id']}_{attachment['name'].replace('/', '_')}"
|
||||||
|
file_path = os.path.join(attachment_dir, attachment_name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(file_path, "wb") as f:
|
||||||
|
f.write(base64.b64decode(attachment["datas"]))
|
||||||
|
|
||||||
|
attachment_info_list.append({
|
||||||
|
"id": attachment["id"],
|
||||||
|
"name": attachment["name"],
|
||||||
|
"file_path": file_path,
|
||||||
|
"mimetype": attachment.get("mimetype"),
|
||||||
|
"create_date": attachment.get("create_date"),
|
||||||
|
"description": attachment.get("description"),
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Erreur lors de l'enregistrement de l'attachement {attachment['name']}: {e}")
|
||||||
|
|
||||||
|
# Sauvegarde des métadonnées dans un fichier JSON
|
||||||
|
attachments_info_path = os.path.join(ticket_dir, "attachments_info.json")
|
||||||
|
with open(attachments_info_path, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(attachment_info_list, f, indent=4, ensure_ascii=False)
|
||||||
|
|
||||||
|
return attachment_info_list
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user