From 0bed166e129a49cad994c75d05d354747deeb9b3 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Mon, 12 May 2025 10:32:19 +0530 Subject: [PATCH] MAY 12: [FIX] Bug Fixed 'chatter_attachments_as_zip' --- chatter_attachments_as_zip/__manifest__.py | 2 +- .../controllers/chatter_attachment_as_zip.py | 16 ++++++++++++---- chatter_attachments_as_zip/doc/RELEASE_NOTES.md | 5 +++++ .../static/src/js/attachment_box_inherit_view.js | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/chatter_attachments_as_zip/__manifest__.py b/chatter_attachments_as_zip/__manifest__.py index 28b1fbe8d..316b28abe 100644 --- a/chatter_attachments_as_zip/__manifest__.py +++ b/chatter_attachments_as_zip/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################### { "name": "Chatter Attachments as ZIP", - "version": "16.0.1.0.0", + "version": "16.0.1.0.1", "category": "Extra Tools", "summary": """Download All Chatter Attachments As A Single Zip File.""", "description": """This module helps to download all chatter attachments diff --git a/chatter_attachments_as_zip/controllers/chatter_attachment_as_zip.py b/chatter_attachments_as_zip/controllers/chatter_attachment_as_zip.py index 3f3c28894..c723c6393 100644 --- a/chatter_attachments_as_zip/controllers/chatter_attachment_as_zip.py +++ b/chatter_attachments_as_zip/controllers/chatter_attachment_as_zip.py @@ -38,12 +38,20 @@ class DownloadAllAttachments(http.Controller): Returns: werkzeug.wrappers.Response: HTTP response with the zip file. """ - chatter_id = request.params.get('res_id') - attachments = request.env['ir.attachment'].search( - [('res_id', '=', chatter_id)]) + res_id = request.params.get('res_id') + res_model = request.params.get('res_model') + + if not res_id or not res_model: + return request.not_found() + + attachments = request.env['ir.attachment'].sudo().search([ + ('res_id', '=', int(res_id)), + ('res_model', '=', res_model), + ('datas', '!=', False), + ]) if attachments: # Define the name of the zip file - zip_filename = f'attachments_{chatter_id}.zip' + zip_filename = f'attachments_{res_id}.zip' # Create a zip file with the attachments and prepare it for download zip_data = io.BytesIO() with zipfile.ZipFile(zip_data, 'w', zipfile.ZIP_DEFLATED) as zipf: diff --git a/chatter_attachments_as_zip/doc/RELEASE_NOTES.md b/chatter_attachments_as_zip/doc/RELEASE_NOTES.md index 3bd1028d6..eeb48d451 100644 --- a/chatter_attachments_as_zip/doc/RELEASE_NOTES.md +++ b/chatter_attachments_as_zip/doc/RELEASE_NOTES.md @@ -4,3 +4,8 @@ #### Version 16.0.1.0.0 #### ADD - Initial commit for Chatter Attachments as ZIP + +#### 05.05.2025 +#### Version 16.0.1.0.1 +#### UPDATE +- Along with res_id, res_model is also passed and checked. diff --git a/chatter_attachments_as_zip/static/src/js/attachment_box_inherit_view.js b/chatter_attachments_as_zip/static/src/js/attachment_box_inherit_view.js index 6b17e711c..92888faaf 100644 --- a/chatter_attachments_as_zip/static/src/js/attachment_box_inherit_view.js +++ b/chatter_attachments_as_zip/static/src/js/attachment_box_inherit_view.js @@ -19,7 +19,7 @@ registerPatch({ return; } // Build the URL with parameters in the query string - const url = `/chatter/attachments/download/zip?res_id=${this.chatter.threadId}`; + const url = `/chatter/attachments/download/zip?res_id=${this.chatter.threadId}&res_model=${this.chatter.thread.model}`; // Send an HTTP GET request to download attachments as a zip file fetch(url) .then(response => {