From 3bf32de4802c43a63b8addd5f29713fd7f2f540f Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Thu, 3 Apr 2025 14:59:35 +0200 Subject: [PATCH] 14:59 --- output/ticket_T11067/all_messages.json | 83 ++++++++++++++++++ output/ticket_T11067/ticket_info.json | 43 +++++++++ retrieve_ticket.py | 30 ++++++- .../attachment_manager.cpython-312.pyc | Bin 1228 -> 3424 bytes utils/attachment_manager.py | 57 +++++++++--- 5 files changed, 199 insertions(+), 14 deletions(-) create mode 100644 output/ticket_T11067/all_messages.json create mode 100644 output/ticket_T11067/ticket_info.json diff --git a/output/ticket_T11067/all_messages.json b/output/ticket_T11067/all_messages.json new file mode 100644 index 0000000..f9a3332 --- /dev/null +++ b/output/ticket_T11067/all_messages.json @@ -0,0 +1,83 @@ +[ + { + "id": 228803, + "body": "", + "author_id": [ + 32165, + "Romuald GRUSON" + ], + "date": "2025-04-02 07:16:48" + }, + { + "id": 227733, + "body": "", + "author_id": [ + 32165, + "Romuald GRUSON" + ], + "date": "2025-03-18 14:19:29" + }, + { + "id": 227732, + "body": "", + "author_id": [ + 32165, + "Romuald GRUSON" + ], + "date": "2025-03-18 14:19:29" + }, + { + "id": 227731, + "body": "

Bonjour,

Effectivement, il y a une anomalie lors du changement du nom d'un poste de production. Les mises à jour déployées ce soir et demain devraient vous permettre d’effectuer cette modification.

\n

Pour cela, il faut éditer le nom du poste de production d’enrobée, l’enregistrer dans la fiche générale, puis cliquer sur la petite flèche à droite du nom et le modifier.

\"image.png\"


Je reste à votre entière disposition pour toute information complémentaire.

Cordialement,

---

Support technique
 

\n

\"CBAO

\n

Afin d'assurer une meilleure traçabilité et vous garantir une prise en charge optimale, nous vous invitons à envoyer vos demandes d'assistance technique à support@cbao.fr
L'objectif du Support Technique est de vous aider : si vous rencontrez une difficulté, ou pour nous soumettre une ou des suggestions d'amélioration de nos logiciels ou de nos méthodes. Notre service est ouvert du lundi au vendredi de 9h à 12h et de 14h à 18h. Dès réception, un technicien prendra en charge votre demande et au besoin vous rappellera.

Confidentialité : Ce courriel contient des informations confidentielles exclusivement réservées au destinataire mentionné. Si vous deviez recevoir cet e-mail par erreur, merci d’en avertir immédiatement l’expéditeur et de le supprimer de votre système informatique. Au cas où vous ne seriez pas destinataire de ce message, veuillez noter que sa divulgation, sa copie ou tout acte en rapport avec la communication du contenu des informations est strictement interdit.

", + "author_id": [ + 32165, + "Romuald GRUSON" + ], + "date": "2025-03-18 14:18:51" + }, + { + "id": 227730, + "body": "", + "author_id": [ + 32165, + "Romuald GRUSON" + ], + "date": "2025-03-18 13:42:15" + }, + { + "id": 227728, + "body": "", + "author_id": [ + 32165, + "Romuald GRUSON" + ], + "date": "2025-03-18 13:42:04" + }, + { + "id": 227726, + "body": "", + "author_id": [ + 2, + "OdooBot" + ], + "date": "2025-03-18 13:22:28" + }, + { + "id": 227725, + "body": "

\r\n\r\n

\r\n
\r\n

Bonjour,\r\n

\r\n

 

\r\n

3 centrales d’enrobage ont changé de nom.

\r\n

 

\r\n

Comment faire ce changement sur BRG-LAB ?

\r\n

 

\r\n

(ici ARMOR ENROBÉS devient BREIZH ENROBÉS sur 3 sites)

\r\n

 

\r\n

\r\n

 

\r\n

Bonne réception

\r\n

 

\r\n

\"cid:image004.png@01D8D425.0F95E5B0\"

\r\n

 

\r\n

Dominique CARVAL

\r\n

 

\r\n

Responsable du pôle Laboratoire Routier

\r\n

Direction des Infrastructures et des mobilités (DIM)

\r\n

Service d’Appui aux Politiques d’Aménagement / Pôle Laboratoire Routier (SAPA/PLR)

\r\n

115, rue du commerce – 56000 VANNES

\r\n

 

\r\n

tél : 02 97 54 71 14 - mobile : 06 98 32 88 30 –\r\ndominique.carval@morbihan.fr\r\n 

\r\n

 

\r\n

 

\r\n

 

\r\n
\r\n
\r\n
Droit à la déconnexion : Si vous recevez ce message en dehors de vos heures de travail ou pendant vos congés, vous n’êtes pas tenu de répondre immédiatement, sauf en cas d’urgence exceptionnelle.\r\n
\r\nCe message électronique et tous les fichiers attachés qu'il contient peuvent être confidentiels, contenir des données personnelles ou sensibles et être soumis au secret professionnel. Il est destiné exclusivement à l'usage du ou des destinataires. Si vous recevez\r\n ce message par erreur et/ou si vous n'êtes pas le destinataire désigné de ce message, le département du Morbihan vous remercie d'avertir immédiatement l'expéditeur et de le détruire ainsi que toutes les pièces jointes s'y rattachant. La publication, l'usage,\r\n la distribution, l'impression ou la copie non autorisée de ce message et des attachements qu'il contient sont strictement interdits. Tout message électronique est susceptible d'altération.
\r\n\r\n", + "author_id": [ + 5144, + "CONSEIL DEPARTEMENTAL DU MORBIHAN (56), Dominique CARVAL" + ], + "date": "2025-03-18 13:18:31" + }, + { + "id": 227724, + "body": "", + "author_id": [ + 2, + "OdooBot" + ], + "date": "2025-03-18 13:22:28" + } +] \ No newline at end of file diff --git a/output/ticket_T11067/ticket_info.json b/output/ticket_T11067/ticket_info.json new file mode 100644 index 0000000..d840b9b --- /dev/null +++ b/output/ticket_T11067/ticket_info.json @@ -0,0 +1,43 @@ +{ + "id": 11046, + "name": "changement nom centrale d'enrobage", + "description": "


", + "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": [] +} \ No newline at end of file diff --git a/retrieve_ticket.py b/retrieve_ticket.py index b300953..a56b248 100755 --- a/retrieve_ticket.py +++ b/retrieve_ticket.py @@ -79,8 +79,32 @@ def main(): # Récupérer et sauvegarder les pièces jointes attachments = attachment_manager.get_ticket_attachments(ticket_id) - attachments_path = os.path.join(output_dir, "attachments_info.json") - save_json(attachments, attachments_path) + attachments_info = [] + 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 structure = { @@ -98,7 +122,7 @@ def main(): print("Extraction terminée avec succès") print(f"- Informations du ticket: {ticket_info_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}") if __name__ == "__main__": diff --git a/utils/__pycache__/attachment_manager.cpython-312.pyc b/utils/__pycache__/attachment_manager.cpython-312.pyc index 81c3235a40217c136e78c2feeda6700e355603ca..e7baacf2b51805db1876b180b796db030af1867f 100644 GIT binary patch literal 3424 zcmbUjTWnOvb>=?yy@WUTcoy?Vw8j}^yacNyT0pvb?$Zj z=o;mN4z+A(35Np+M(>4xr&fFj{Yxy|q12I$cL2GH2qHLx;7|6foz`8jF!_u zS-GyDn1rojy%7a)6%}z2X@J#6QGykAR|_bHCu0&<@+6;Ue%KaXF=-~r!(vM_a;Bx{ z64arYLTWS`eKs^OozK#NWQytL!Gu1L$z%^&Mq-9qM+RmsBV!Keo7!sGn!5dk1@6;8 zpkZm+V#f>S^t&`j24rpn@FA+UbT2EH{MC-$W#u=K4cJ56U%N;%2=_2*&9Ypg9$Z02 z;X79g~XE6iT5f6!T6lh7H!=@D2}}RA-54jZvL&KclARM3v(=gn1^I8S`)n zj8#OOxeDp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z2J%Lw(eZtAq;zR0Co4=^4|2`3f&Bq;`R^US&jb8_U%~C+xNZrDJ9NE`1Oh2fcsFEiG|}kH!l$nBkf!}|R?pNaGJMZWJUCp2?}3Su$;4;L z#PiJd2`~cS56F4{oxEhC=W>8(#LPJW7tq&|r0y^GY#^A{eX4pKmyWC>F_(|7D9~;6 zti1oHrpl4A4QF$`X|LK_>RCrHtpFoTU!1Z}zH7f1x6f$yds^k>2bBrkA=t^ZJ(IT! zrae1v7v?K73zg*J6LF-blTat-X9Gg3R|R+-0QW${1~uk+i$o_;GvKEJ6HSd{)HC1f uH4nYXCSXsr38wh|Azm0iLjFf6{0IgAf%a9=C>^8kOiEK_%CAV1 zO49TsResBp-X3c*>8n686{?adt4hl|2V3xKF&Tipiu~@y4QoZ*&Q-@wX&e*48BfzJ zXi)dzJ3b9?j|}OM@WO!5hdehUs`0EM&oQI2RxvTStzLh6tG4f5>+<`^Qm4tDbvjvC3M{8T8Sb-gNf4D;U-kHGCbdrD$`34bx`Z- zoh=pHH7m@v3tOqmqyaw&$9v7DrW%=}UPbxBli_bUd z|2@kP#k>V@hy1?u^3n3@(b@X_)%*R?^5utD-XAS}Fk1ZZ=*&wGFRYK2uRpE?r>l3v zagCf>{JQ^T|Cfc8!-bX6>h=9=KQG)Im2c_=h_o5a;dQ~|;M`R?9$+s+y~g=xJ&{c; z8effm0l@ib$7-xg<4bnFv0CF@(iZ@}BSqArUX7Ql0CY5$0rtq)qrtgvJ~}2ajKflJ zi~it`36A@0|Gk6N19Nck$Bz%!Z~s*+PNHF;O?Yyl?RV2oa>8B^yBa>b+5MknT2Q}= u{8(g>&eQUZNo{ZF*I*5Q6Xra?*r$~KMph2V%CF>=zu6qUMV}DFV(&koZ8<9d diff --git a/utils/attachment_manager.py b/utils/attachment_manager.py index 5fc30b9..d355773 100644 --- a/utils/attachment_manager.py +++ b/utils/attachment_manager.py @@ -1,15 +1,50 @@ +import os +import base64 +import json from typing import List, Dict, Any -from .auth_manager import AuthManager +from datetime import datetime class AttachmentManager: - def __init__(self, auth: AuthManager): - self.auth = auth + def __init__(self, odoo_instance, model_name: str = "project.task"): + self.odoo = odoo_instance + self.model_name = model_name - def get_ticket_attachments(self, ticket_id: int) -> List[Dict[str, Any]]: - params = { - "model": "ir.attachment", - "method": "search_read", - "args": [[[ "res_id", "=", ticket_id], ["res_model", "=", "project.task"]]], - "kwargs": {"fields": ["id", "name", "datas"]} - } - return self.auth._rpc_call("/web/dataset/call_kw", params) + def fetch_attachments(self, ticket_id: int) -> List[Dict[str, Any]]: + attachments = self.odoo.execute('ir.attachment', 'search_read', [ + [('res_model', '=', self.model_name), ('res_id', '=', ticket_id)] + ], ['id', 'name', 'datas', 'mimetype', 'create_date', 'description']) + + return attachments if isinstance(attachments, list) else [] + + 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