From 50d2472379679e1f2dd9a8a1a55b4a1f142ba71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 1 Oct 2024 16:30:42 +0200 Subject: [PATCH] [MIG] dms_attachment_link: Finish migration [UPD] Update dms_attachment_link.pot --- dms_attachment_link/i18n/dms_attachment_link.pot | 9 +++++++-- dms_attachment_link/models/__init__.py | 1 + dms_attachment_link/models/ir_attachment.py | 2 +- dms_attachment_link/models/ir_binary.py | 15 +++++++++++++++ .../tests/test_dms_attachment_link.py | 13 +++++++------ 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 dms_attachment_link/models/ir_binary.py diff --git a/dms_attachment_link/i18n/dms_attachment_link.pot b/dms_attachment_link/i18n/dms_attachment_link.pot index d1e7b52dd..a4f479d45 100644 --- a/dms_attachment_link/i18n/dms_attachment_link.pot +++ b/dms_attachment_link/i18n/dms_attachment_link.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 15.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" @@ -19,7 +19,7 @@ msgid "Add" msgstr "" #. module: dms_attachment_link -#. openerp-web +#. odoo-javascript #: code:addons/dms_attachment_link/static/src/xml/chatter.xml:0 #, python-format msgid "Add DMS File" @@ -40,6 +40,11 @@ msgstr "" msgid "File" msgstr "" +#. module: dms_attachment_link +#: model:ir.model,name:dms_attachment_link.model_ir_binary +msgid "File streaming helper model for controllers" +msgstr "" + #. module: dms_attachment_link #: model:ir.actions.act_window,name:dms_attachment_link.action_dms_file_wizard_selector_dms_attachment_link msgid "Files" diff --git a/dms_attachment_link/models/__init__.py b/dms_attachment_link/models/__init__.py index 1cce9f551..c0811a10f 100644 --- a/dms_attachment_link/models/__init__.py +++ b/dms_attachment_link/models/__init__.py @@ -1,2 +1,3 @@ from . import dms_file from . import ir_attachment +from . import ir_binary diff --git a/dms_attachment_link/models/ir_attachment.py b/dms_attachment_link/models/ir_attachment.py index 54967ac1c..d38fa20d5 100644 --- a/dms_attachment_link/models/ir_attachment.py +++ b/dms_attachment_link/models/ir_attachment.py @@ -9,7 +9,7 @@ class IrAttachment(models.Model): dms_file_id = fields.Many2one(comodel_name="dms.file") - @api.depends("dms_file_id.content") + @api.depends("dms_file_id", "dms_file_id.content") def _compute_datas(self): """Get the contents of the attachment directly from the DMS file.""" _self = self.filtered("dms_file_id") diff --git a/dms_attachment_link/models/ir_binary.py b/dms_attachment_link/models/ir_binary.py new file mode 100644 index 000000000..1ee687ead --- /dev/null +++ b/dms_attachment_link/models/ir_binary.py @@ -0,0 +1,15 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models + + +class IrBinary(models.AbstractModel): + _inherit = "ir.binary" + + def _record_to_stream(self, record, field_name): + """We need to overwrite for the download and preview to be correct.""" + if record._name == "ir.attachment" and record.dms_file_id: + record = record.dms_file_id + field_name = "content" + return super()._record_to_stream(record=record, field_name=field_name) diff --git a/dms_attachment_link/tests/test_dms_attachment_link.py b/dms_attachment_link/tests/test_dms_attachment_link.py index 684a3849f..84935eae7 100644 --- a/dms_attachment_link/tests/test_dms_attachment_link.py +++ b/dms_attachment_link/tests/test_dms_attachment_link.py @@ -1,14 +1,15 @@ # Copyright 2023 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests import common +from odoo.addons.base.tests.common import BaseCommon -class TestDmsAttachmentLink(common.TransactionCase): - def setUp(self): - super().setUp() - self.partner = self.env["res.partner"].create({"name": "Test partner"}) - self.dms_file = self.env.ref("dms.file_01_demo") +class TestDmsAttachmentLink(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test partner"}) + cls.dms_file = cls.env.ref("dms.file_01_demo") def test_add_url_attachment(self): attachment = self.dms_file.with_context(