From 95c078588d571dca222b444c0d3b30862231b9e7 Mon Sep 17 00:00:00 2001 From: matiasperalta1 Date: Mon, 18 Jul 2022 16:33:26 -0300 Subject: [PATCH] [MIG] document_url: Migration to 15.0 --- document_url/README.rst | 1 + document_url/__manifest__.py | 13 ++++-- document_url/readme/CONTRIBUTORS.rst | 1 + document_url/static/src/js/url.esm.js | 49 +++++++++++++++++++++ document_url/static/src/js/url.js | 42 ------------------ document_url/static/src/xml/url.xml | 57 +++++++++++++++++-------- document_url/tests/test_document_url.py | 14 +++--- document_url/view/document_url_view.xml | 39 ++++++----------- document_url/wizard/document_url.py | 2 +- 9 files changed, 122 insertions(+), 96 deletions(-) create mode 100644 document_url/static/src/js/url.esm.js delete mode 100644 document_url/static/src/js/url.js diff --git a/document_url/README.rst b/document_url/README.rst index 0aca1fad..ecdddee6 100644 --- a/document_url/README.rst +++ b/document_url/README.rst @@ -72,6 +72,7 @@ Contributors * Ernesto Tejeda * Manuel Calero * Víctor Martínez + * Matias Peralta - Adhoc SA Maintainers ~~~~~~~~~~~ diff --git a/document_url/__manifest__.py b/document_url/__manifest__.py index 0f9d1965..6f81feed 100644 --- a/document_url/__manifest__.py +++ b/document_url/__manifest__.py @@ -2,16 +2,23 @@ # Copyright 2020 Tecnativa - Manuel Calero { "name": "URL attachment", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "category": "Tools", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/knowledge", "license": "AGPL-3", "depends": ["mail"], "data": [ - "view/document_url_view.xml", "security/ir.model.access.csv", + "view/document_url_view.xml", ], - "qweb": ["static/src/xml/url.xml"], + "assets": { + "web.assets_backend": [ + "document_url/static/src/js/url.esm.js", + ], + "web.assets_qweb": [ + "document_url/static/src/xml/url.xml", + ], + }, "installable": True, } diff --git a/document_url/readme/CONTRIBUTORS.rst b/document_url/readme/CONTRIBUTORS.rst index f923719f..ad7a42c2 100644 --- a/document_url/readme/CONTRIBUTORS.rst +++ b/document_url/readme/CONTRIBUTORS.rst @@ -5,3 +5,4 @@ * Ernesto Tejeda * Manuel Calero * Víctor Martínez + * Matias Peralta - Adhoc SA diff --git a/document_url/static/src/js/url.esm.js b/document_url/static/src/js/url.esm.js new file mode 100644 index 00000000..99f5a4fb --- /dev/null +++ b/document_url/static/src/js/url.esm.js @@ -0,0 +1,49 @@ +/** @odoo-module **/ + +import {AttachmentBox} from "@mail/components/attachment_box/attachment_box"; +import {AttachmentCard} from "@mail/components/attachment_card/attachment_card"; +import {patch} from "web.utils"; + +patch(AttachmentBox.prototype, "document_url/static/src/js/url.js", { + _onAddUrl(event) { + event.preventDefault(); + event.stopPropagation(); + this.env.bus.trigger("do-action", { + action: "document_url.action_ir_attachment_add_url", + options: { + additional_context: { + active_id: this.messaging.models["mail.chatter"].get( + this.props.chatterLocalId + ).threadId, + active_ids: [ + this.messaging.models["mail.chatter"].get( + this.props.chatterLocalId + ).threadId, + ], + active_model: this.messaging.models["mail.chatter"].get( + this.props.chatterLocalId + ).threadModel, + }, + on_close: this._onAddedUrl.bind(this), + }, + }); + }, + _onAddedUrl() { + this.trigger("reload"); + }, +}); + +patch(AttachmentCard.prototype, "document_url/static/src/js/url.js", { + /** + * Return the url of the attachment. Temporary attachments, a.k.a. uploading + * attachments, do not have an url. + * + * @returns {String} + */ + get attachmentUrl() { + return this.env.session.url("/web/content", { + id: this.attachmentCard.attachment.id, + download: true, + }); + }, +}); diff --git a/document_url/static/src/js/url.js b/document_url/static/src/js/url.js deleted file mode 100644 index 2cc2b33a..00000000 --- a/document_url/static/src/js/url.js +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) - * Pedro M. Baeza - * Copyright 2016 ACSONE SA/NV () - * Copyright 2019 Tecnativa - Ernesto Tejeda - * Copyright 2020 Tecnativa - Manuel Calero - * Copyright 2021 Tecnativa - Víctor Martínez - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - */ -odoo.define("document_url", function (require) { - "use strict"; - - const AttachmentBox = require("mail/static/src/components/attachment_box/attachment_box.js"); - const Attachment = require("mail/static/src/components/attachment/attachment.js"); - const {patch} = require("web.utils"); - - patch(AttachmentBox, "document_url", { - _onAddUrl() { - this.env.bus.trigger("do-action", { - action: "document_url.action_ir_attachment_add_url", - options: { - additional_context: { - active_id: this.thread.id, - active_ids: [this.thread.id], - active_model: this.thread.model, - }, - on_close: this._onAddedUrl.bind(this), - }, - }); - }, - _onAddedUrl() { - this.trigger("reload"); - }, - }); - patch(Attachment, "document_url", { - _onClickImage(ev) { - if (!this.attachment.isViewable) { - this._onClickDownload(ev); - } - this._super.apply(this, arguments); - }, - }); -}); diff --git a/document_url/static/src/xml/url.xml b/document_url/static/src/xml/url.xml index 6a139db5..b0855c3a 100644 --- a/document_url/static/src/xml/url.xml +++ b/document_url/static/src/xml/url.xml @@ -2,43 +2,66 @@ - + - - + + + - + + - + + + - attachment.mimetype != 'application/link' + attachmentCard.attachment.mimetype != 'application/link' - - attachment.mimetype != 'application/link' + + attachmentCard.attachment.mimetype != 'application/link' - + diff --git a/document_url/tests/test_document_url.py b/document_url/tests/test_document_url.py index 45ee2ed0..47c7122a 100644 --- a/document_url/tests/test_document_url.py +++ b/document_url/tests/test_document_url.py @@ -7,14 +7,12 @@ class TestDocumentUrl(common.TransactionCase): def setUp(self): super().setUp() wizard_add_url = self.env["ir.attachment.add_url"] - ctx = { - "active_model": "res.users", - "active_id": self.env.ref("base.user_demo").id, - "active_ids": [self.env.ref("base.user_demo").id], - } - self.wizard_add_url = wizard_add_url.with_context(ctx).create( - {"name": "Demo User (Website)", "url": "http://www.odoodemouser.com"} - ) + + self.wizard_add_url = wizard_add_url.with_context( + active_model="res.users", + active_id=self.env.ref("base.user_demo").id, + active_ids=[self.env.ref("base.user_demo").id], + ).create({"name": "Demo User (Website)", "url": "http://www.odoodemouser.com"}) def test_add_url_attachment(self): self.wizard_add_url.action_add_url() diff --git a/document_url/view/document_url_view.xml b/document_url/view/document_url_view.xml index 1403b168..5c0b208a 100644 --- a/document_url/view/document_url_view.xml +++ b/document_url/view/document_url_view.xml @@ -1,26 +1,14 @@ -