diff --git a/attachment_zipped_download/__manifest__.py b/attachment_zipped_download/__manifest__.py index df4b7908..ab7a08db 100644 --- a/attachment_zipped_download/__manifest__.py +++ b/attachment_zipped_download/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Attachment Zipped Download", - "version": "16.0.1.0.0", + "version": "16.0.1.0.1", "category": "Tools", "website": "https://github.com/OCA/knowledge", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/attachment_zipped_download/controllers/main.py b/attachment_zipped_download/controllers/main.py index fe9a4fd2..f4b5f973 100644 --- a/attachment_zipped_download/controllers/main.py +++ b/attachment_zipped_download/controllers/main.py @@ -12,9 +12,7 @@ class AttachmentZippedDownloadController(http.Controller): if len(ids) == 0: return list_ids = map(int, ids.split(",")) - out_file = ( - request.env["ir.attachment"].sudo().browse(list_ids)._create_temp_zip() - ) + out_file = request.env["ir.attachment"].browse(list_ids)._create_temp_zip() return http.send_file( filepath_or_fp=out_file, mimetype="application/zip", diff --git a/attachment_zipped_download/tests/test_attachment_zipped_download.py b/attachment_zipped_download/tests/test_attachment_zipped_download.py index c6b8ef90..84a8910e 100644 --- a/attachment_zipped_download/tests/test_attachment_zipped_download.py +++ b/attachment_zipped_download/tests/test_attachment_zipped_download.py @@ -1,36 +1,43 @@ -# Copyright 2022 Tecnativa - Víctor Martínez +# Copyright 2022-2023 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import base64 import odoo.tests +from odoo.tests import new_test_user class TestAttachmentZippedDownload(odoo.tests.HttpCase): def setUp(self): super().setUp() - test_1 = self._create_attachment("test1.txt") - test_2 = self._create_attachment("test2.txt") - self.attachments = test_1 + test_2 - self.user = self.env["res.users"].create( - { - "name": "test-user", - "login": "test-user", - "password": "test-user", - "groups_id": [(6, 0, [self.env.ref("base.group_user").id])], - } + ctx = { + "mail_create_nolog": True, + "mail_create_nosubscribe": True, + "mail_notrack": True, + "no_reset_password": True, + } + self.user = new_test_user( + self.env, + login="test-user", + context=ctx, ) + test_1 = self._create_attachment(self.user, "test1.txt") + test_2 = self._create_attachment(self.user, "test2.txt") + self.attachments = test_1 + test_2 - def _create_attachment(self, name): - return self.env["ir.attachment"].create( - { - "name": name, - "datas": base64.b64encode(b"\xff data"), - } + def _create_attachment(self, user, name): + return ( + self.env["ir.attachment"] + .with_user(user) + .create( + { + "name": name, + "datas": base64.b64encode(b"\xff data"), + } + ) ) def test_action_attachments_download(self): self.authenticate("test-user", "test-user") - # 16.0 WARNING odoo odoo.http: Sorry, you are not allowed to access this document. - res = self.attachments.sudo().action_attachments_download() + res = self.attachments.action_attachments_download() response = self.url_open(res["url"], timeout=20) self.assertEqual(response.status_code, 200)