[MIG] document_url: Migration to 15.0

This commit is contained in:
matiasperalta1 2022-07-18 16:33:26 -03:00 committed by Bhavesh Heliconia
parent 620aac5041
commit 95c078588d
9 changed files with 122 additions and 96 deletions

View File

@ -72,6 +72,7 @@ Contributors
* Ernesto Tejeda
* Manuel Calero
* Víctor Martínez
* Matias Peralta - Adhoc SA
Maintainers
~~~~~~~~~~~

View File

@ -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,
}

View File

@ -5,3 +5,4 @@
* Ernesto Tejeda
* Manuel Calero
* Víctor Martínez
* Matias Peralta - Adhoc SA

View File

@ -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,
});
},
});

View File

@ -1,42 +0,0 @@
/* Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
* 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);
},
});
});

View File

@ -2,9 +2,21 @@
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda
Copyright 2021 Tecnativa - Víctor Martínez
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates xml:space="preserve">
<templates>
<t t-inherit="mail.AttachmentBox" t-inherit-mode="extension" owl="1">
<xpath expr="//button[hasclass('o_AttachmentBox_buttonAdd')]" position="after">
<xpath
expr="//button[hasclass('o_AttachmentBox_buttonAdd')]"
position="replace"
>
<div align="center">
<button
class="o_AttachmentBox_buttonAdd btn btn-link"
type="button"
t-on-click="_onClickAdd"
>
<i class="fa fa-plus-square" />
Add attachments
</button>
<button
type="button"
class="o_add_url_button btn btn-link"
@ -13,32 +25,43 @@
<i class="fa fa-plus-square" />
Add URL
</button>
</div>
</xpath>
</t>
<t t-inherit="mail.Attachment" t-inherit-mode="extension" owl="1">
<t t-inherit="mail.AttachmentCard" t-inherit-mode="extension" owl="1">
<xpath
expr="//t[@t-if='attachment']/t/div[1][hasclass('o_Attachment_details')]//div[hasclass('o_Attachment_filename')]/t"
expr="//div[hasclass('o_AttachmentCard_details')]/t/div"
position="replace"
>
<a t-att-href="attachmentUrl" target="new">
<t t-esc="attachment.displayName" />
<t t-esc="attachmentCard.attachment.displayName" />
</a>
</xpath>
<xpath
expr="//div[hasclass('o_Attachment_asideItemDownload')]"
expr="//div[hasclass('o_AttachmentCard_details')]/t[2]/div"
position="replace"
>
</xpath>
<xpath
expr="//div[hasclass('o_AttachmentCard_asideItemDownload')]"
position="attributes"
>
<attribute name="t-if">attachment.mimetype != 'application/link'</attribute>
<attribute
name="t-if"
>attachmentCard.attachment.mimetype != 'application/link'</attribute>
</xpath>
<xpath expr="//div[hasclass('o_Attachment_image')]" position="attributes">
<attribute name="t-if">attachment.mimetype != 'application/link'</attribute>
<xpath expr="//div[hasclass('o_AttachmentCard_image')]" position="attributes">
<attribute
name="t-if"
>attachmentCard.attachment.mimetype != 'application/link'</attribute>
</xpath>
<xpath expr="//div[hasclass('o_Attachment_image')]" position="before">
<xpath expr="//div[hasclass('o_AttachmentCard_image')]" position="before">
<a
class="o_Attachment_url_icon"
t-att-href="attachmentUrl"
target="new"
t-if="attachment.mimetype=='application/link'"
t-if="attachmentCard.attachment.mimetype=='application/link'"
>
<i class="fa fa-link fa-2x" />
</a>

View File

@ -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()

View File

@ -1,26 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="assets_backend"
name="document_url assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script type="text/javascript" src="/document_url/static/src/js/url.js" />
<link
href="/document_url/static/src/scss/document_url.scss"
rel="stylesheet"
/>
</xpath>
</template>
<record model="ir.actions.act_window" id='action_ir_attachment_add_url'>
<field name="name">Add URL</field>
<field name="res_model">ir.attachment.add_url</field>
<field name="type">ir.actions.act_window</field>
<field name="target">new</field>
<field name="view_mode">form</field>
<record id='action_ir_attachment_add_url' model='ir.actions.act_window'>
<field name='name'>Add URL</field>
<field name='res_model'>ir.attachment.add_url</field>
<field name='type'>ir.actions.act_window</field>
<field name='target'>new</field>
<field name='view_mode'>form</field>
</record>
<record model="ir.ui.view" id="view_ir_attachment_add_url_form">
<data>
<record id="view_ir_attachment_add_url_form" model="ir.ui.view">
<field name="name">ir.attachment.add_url.form</field>
<field name="model">ir.attachment.add_url</field>
<field name="arch" type="xml">
@ -42,4 +30,5 @@
</form>
</field>
</record>
</data>
</odoo>

View File

@ -10,7 +10,7 @@ class AddUrlWizard(models.TransientModel):
_name = "ir.attachment.add_url"
_description = "Wizard to add URL attachment"
name = fields.Char("Name", required=True)
name = fields.Char(required=True)
url = fields.Char("URL", required=True)
def action_add_url(self):