[FIX] document_url: Always add attachment filename

In v12, if you browse to a record that has an URL attachment, you'll get an error because its `filename` will be `False` and that will make [this line][1] fail.

To avoid that problem:

1. A migration script ensures URL attachments always have a filename.
2. From now on, created URL attachments with this module will also have a filename.
3. The filename used is the name.

[1]: 66c5053a3d/addons/mail/static/src/xml/thread.xml (L506)
This commit is contained in:
Jairo Llopis 2019-09-20 15:18:42 +01:00
parent 169eebd7f6
commit 5b8879583d
No known key found for this signature in database
GPG Key ID: 59564BF1E22F314F
4 changed files with 15 additions and 3 deletions

View File

@ -3,7 +3,7 @@
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
{
'name': 'URL attachment',
'version': '12.0.1.0.0',
'version': '12.0.1.1.0',
'category': 'Tools',
'author': "Tecnativa,"
"Odoo Community Association (OCA)",

View File

@ -0,0 +1,10 @@
# Copyright 2019 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
def migrate(cr, version):
"""Stored URLs need to define a filename."""
cr.execute("""
UPDATE ir_attachment
SET filename = name
WHERE filename IS NULL AND type = 'url'
""")

View File

@ -26,5 +26,6 @@ class TestDocumentUrl(common.TransactionCase):
('res_model', '=', 'res.users'),
('res_id', '=', self.env.ref('base.user_demo').id)
]
attachment_added_count = self.env['ir.attachment'].search_count(domain)
self.assertEqual(attachment_added_count, 1)
attachment_added = self.env['ir.attachment'].search(domain)
self.assertEqual(len(attachment_added), 1)
self.assertEqual(attachment_added.filename, 'Demo User (Website)')

View File

@ -24,6 +24,7 @@ class AddUrlWizard(models.Model):
for active_id in self.env.context.get('active_ids', []):
attachment = {
'name': form.name,
'filename': form.name,
'type': 'url',
'url': url.geturl(),
'res_id': active_id,