Skip to content

Commit a2b7c16

Browse files
committed
[MIG] dms_attachment_link: Finish migration
1 parent 21643cf commit a2b7c16

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import dms_file
22
from . import ir_attachment
3+
from . import ir_binary

dms_attachment_link/models/ir_attachment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IrAttachment(models.Model):
99

1010
dms_file_id = fields.Many2one(comodel_name="dms.file")
1111

12-
@api.depends("dms_file_id.content")
12+
@api.depends("dms_file_id", "dms_file_id.content")
1313
def _compute_datas(self):
1414
"""Get the contents of the attachment directly from the DMS file."""
1515
_self = self.filtered("dms_file_id")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2024 Tecnativa - Víctor Martínez
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
from odoo import models
5+
6+
7+
class IrBinary(models.AbstractModel):
8+
_inherit = "ir.binary"
9+
10+
def _record_to_stream(self, record, field_name):
11+
"""We need to overwrite for the download and preview to be correct."""
12+
if record._name == "ir.attachment" and record.dms_file_id:
13+
record = record.dms_file_id
14+
field_name = "content"
15+
return super()._record_to_stream(record=record, field_name=field_name)

dms_attachment_link/tests/test_dms_attachment_link.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Copyright 2023 Tecnativa - Víctor Martínez
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo.tests import common
4+
from odoo.addons.base.tests.common import BaseCommon
55

66

7-
class TestDmsAttachmentLink(common.TransactionCase):
8-
def setUp(self):
9-
super().setUp()
10-
self.partner = self.env["res.partner"].create({"name": "Test partner"})
11-
self.dms_file = self.env.ref("dms.file_01_demo")
7+
class TestDmsAttachmentLink(BaseCommon):
8+
@classmethod
9+
def setUpClass(cls):
10+
super().setUpClass()
11+
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
12+
cls.dms_file = cls.env.ref("dms.file_01_demo")
1213

1314
def test_add_url_attachment(self):
1415
attachment = self.dms_file.with_context(

0 commit comments

Comments
 (0)