[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).

This commit is contained in:
Víctor Martínez 2022-01-20 14:04:55 +01:00
parent b20fd056b1
commit 22218ade21
4 changed files with 27 additions and 2 deletions

View File

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

View File

@ -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'
""",
)

View File

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

View File

@ -10,6 +10,7 @@
<link
href="/document_url/static/src/scss/document_url.scss"
rel="stylesheet"
type="text/scss"
/>
</xpath>
</template>