Skip to content

Commit

Permalink
[MIG] dms_attachment_link: Finish migration
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralmau committed Oct 1, 2024
1 parent 21643cf commit a2b7c16
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions dms_attachment_link/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import dms_file
from . import ir_attachment
from . import ir_binary
2 changes: 1 addition & 1 deletion dms_attachment_link/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions dms_attachment_link/models/ir_binary.py
Original file line number Diff line number Diff line change
@@ -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"

Check warning on line 14 in dms_attachment_link/models/ir_binary.py

View check run for this annotation

Codecov / codecov/patch

dms_attachment_link/models/ir_binary.py#L13-L14

Added lines #L13 - L14 were not covered by tests
return super()._record_to_stream(record=record, field_name=field_name)
13 changes: 7 additions & 6 deletions dms_attachment_link/tests/test_dms_attachment_link.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit a2b7c16

Please sign in to comment.