From 22218ade21d083ce98688888fed96d9b5a066ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Thu, 20 Jan 2022 14:04:55 +0100 Subject: [PATCH] [FIX] document_url: Improve the definition of mimetype=application/link only to records linked to a model to avoid errors with the developer model (with assets). --- document_url/__manifest__.py | 2 +- .../migrations/14.0.1.1.0/post-migration.py | 24 +++++++++++++++++++ document_url/models/ir_attachment.py | 2 +- document_url/view/document_url_view.xml | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 document_url/migrations/14.0.1.1.0/post-migration.py diff --git a/document_url/__manifest__.py b/document_url/__manifest__.py index 0f9d1965..be72c409 100644 --- a/document_url/__manifest__.py +++ b/document_url/__manifest__.py @@ -2,7 +2,7 @@ # Copyright 2020 Tecnativa - Manuel Calero { "name": "URL attachment", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "category": "Tools", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/knowledge", diff --git a/document_url/migrations/14.0.1.1.0/post-migration.py b/document_url/migrations/14.0.1.1.0/post-migration.py new file mode 100644 index 00000000..3f2df440 --- /dev/null +++ b/document_url/migrations/14.0.1.1.0/post-migration.py @@ -0,0 +1,24 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.logged_query( + env.cr, + """ + UPDATE ir_attachment + SET mimetype = 'text/css' + WHERE mimetype = 'application/link' AND res_id = 0 AND name LIKE '%.%css' + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE ir_attachment + SET mimetype = 'application/javascript' + WHERE mimetype = 'application/link' AND res_id = 0 AND name LIKE '%.js' + """, + ) diff --git a/document_url/models/ir_attachment.py b/document_url/models/ir_attachment.py index 0413ae1c..04383ec5 100644 --- a/document_url/models/ir_attachment.py +++ b/document_url/models/ir_attachment.py @@ -8,6 +8,6 @@ class IrAttachment(models.Model): _inherit = "ir.attachment" def _compute_mimetype(self, values): - if values.get("url"): + if values.get("url") and values.get("res_model") and values.get("res_id"): return "application/link" return super()._compute_mimetype(values) diff --git a/document_url/view/document_url_view.xml b/document_url/view/document_url_view.xml index 1403b168..8796420d 100644 --- a/document_url/view/document_url_view.xml +++ b/document_url/view/document_url_view.xml @@ -10,6 +10,7 @@