From c212cfe8992292f57acacd809de26e1817533095 Mon Sep 17 00:00:00 2001 From: Thanh Dodeur Date: Fri, 5 Apr 2019 08:11:26 +0000 Subject: [PATCH] [REF] *: removes datas_fname from ir.attachment This commit removes the field `datas_fname` from `ir.attachment` as it was unnecessary and most of the time the duplicate of `name` or `url`. Task #1909865 closes odoo/odoo#32976 Signed-off-by: Martin Geubelle (mge) --- .../account_facturx/models/account_invoice.py | 4 +- .../models/ir_attachment.py | 4 +- addons/base_import_module/models/ir_module.py | 1 - addons/calendar/models/calendar.py | 1 - addons/crm/data/crm_lead_demo.xml | 1 - .../data/hr_recruitment_demo.xml | 3 - .../tests/test_recruitment_process.py | 2 +- addons/l10n_be_edi/models/account_invoice.py | 1 - addons/l10n_be_edi/tests/test_ubl.py | 1 - .../data/account_invoice_demo.xml | 3 +- addons/l10n_it_edi/models/account_invoice.py | 2 - addons/l10n_it_edi/models/ir_mail_server.py | 1 - addons/mail/data/mail_demo.xml | 6 +- addons/mail/models/mail_mail.py | 4 +- addons/mail/models/mail_message.py | 5 +- addons/mail/models/mail_template.py | 1 - addons/mail/models/mail_thread.py | 1 - addons/mail/static/src/js/attachment_box.js | 2 +- addons/mail/static/src/js/chatter.js | 2 +- addons/mail/static/tests/chatter_tests.js | 20 ++- .../static/tests/document_viewer_tests.js | 14 +- addons/mail/views/mail_message_views.xml | 10 +- addons/mail/wizard/mail_compose_message.py | 1 - .../mass_mailing/data/mass_mailing_demo.xml | 1 - addons/mass_mailing/models/mass_mailing.py | 3 +- addons/mrp/views/ir_attachment_view.xml | 3 +- addons/snailmail/models/snailmail_letter.py | 3 +- addons/test_mail/tests/test_mail_message.py | 3 +- addons/test_mail/tests/test_mail_template.py | 6 +- .../test_mail/tests/test_message_compose.py | 4 +- addons/test_mail/tests/test_odoobot.py | 1 - addons/test_mail/tests/test_performance.py | 3 +- addons/web/controllers/main.py | 7 +- .../static/src/js/fields/relational_fields.js | 1 - .../tests/fields/relational_fields_tests.js | 2 +- addons/web_editor/models/assets.py | 3 +- .../static/src/js/wysiwyg/plugin/media.js | 1 - .../static/src/js/wysiwyg/widgets/media.js | 8 +- addons/web_editor/static/tests/test_utils.js | 5 - addons/web_unsplash/controllers/main.py | 3 +- addons/website/data/website_data.xml | 147 ++++++------------ addons/website/models/ir_http.py | 2 +- .../static/src/js/editor/wysiwyg_multizone.js | 1 - addons/website/views/ir_attachment_views.xml | 2 +- .../website_blog/data/website_blog_data.xml | 2 - addons/website_form/controllers/main.py | 1 - .../data/product_demo.xml | 1 - .../models/ir_module_module.py | 1 - .../models/theme_models.py | 1 - odoo/addons/base/models/assetsbundle.py | 11 +- odoo/addons/base/models/ir_actions_report.py | 3 +- odoo/addons/base/models/ir_attachment.py | 13 +- odoo/addons/base/models/ir_http.py | 4 +- odoo/addons/base/tests/test_ir_http.py | 9 +- .../addons/base/views/ir_attachment_views.xml | 6 +- 55 files changed, 119 insertions(+), 232 deletions(-) diff --git a/addons/account_facturx/models/account_invoice.py b/addons/account_facturx/models/account_invoice.py index 169ce4b45e6..b46cb3b6975 100644 --- a/addons/account_facturx/models/account_invoice.py +++ b/addons/account_facturx/models/account_invoice.py @@ -308,7 +308,7 @@ class AccountInvoice(models.Model): try: tree = etree.fromstring(content) except Exception: - raise UserError(_('The xml file is badly formatted : {}').format(attachment.datas_fname)) + raise UserError(_('The xml file is badly formatted : {}').format(attachment.name)) for xml_type, check_func, decode_func in decoders: check_res = check_func(tree) @@ -327,4 +327,4 @@ class AccountInvoice(models.Model): try: return invoice except UnboundLocalError: - raise UserError(_('No decoder was found for the xml file: {}. The file is badly formatted, not supported or the decoder is not installed').format(attachment.datas_fname)) + raise UserError(_('No decoder was found for the xml file: {}. The file is badly formatted, not supported or the decoder is not installed').format(attachment.name)) diff --git a/addons/attachment_indexation/models/ir_attachment.py b/addons/attachment_indexation/models/ir_attachment.py index bdc4559e893..dcc662a3c5d 100644 --- a/addons/attachment_indexation/models/ir_attachment.py +++ b/addons/attachment_indexation/models/ir_attachment.py @@ -107,10 +107,10 @@ class IrAttachment(models.Model): return buf @api.model - def _index(self, bin_data, datas_fname, mimetype): + def _index(self, bin_data, mimetype): for ftype in FTYPES: buf = getattr(self, '_index_%s' % ftype)(bin_data) if buf: return buf - return super(IrAttachment, self)._index(bin_data, datas_fname, mimetype) + return super(IrAttachment, self)._index(bin_data, mimetype) diff --git a/addons/base_import_module/models/ir_module.py b/addons/base_import_module/models/ir_module.py index 62887f6c5e4..8ac8e59b92b 100644 --- a/addons/base_import_module/models/ir_module.py +++ b/addons/base_import_module/models/ir_module.py @@ -95,7 +95,6 @@ class IrModule(models.Model): filename = os.path.split(url_path)[1] values = dict( name=filename, - datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py index 98ea38b9bfa..16a95ffdbd6 100644 --- a/addons/calendar/models/calendar.py +++ b/addons/calendar/models/calendar.py @@ -207,7 +207,6 @@ class Attendee(models.Model): email_values['attachment_ids'] = [ (0, 0, {'name': 'invitation.ics', 'mimetype': 'text/calendar', - 'datas_fname': 'invitation.ics', 'datas': base64.b64encode(ics_file)}) ] mail_ids.append(invitation_template.send_mail(attendee.id, email_values=email_values, notif_layout='mail.mail_notification_light')) diff --git a/addons/crm/data/crm_lead_demo.xml b/addons/crm/data/crm_lead_demo.xml index 0e73640175a..d8ee46c8982 100644 --- a/addons/crm/data/crm_lead_demo.xml +++ b/addons/crm/data/crm_lead_demo.xml @@ -444,7 +444,6 @@ Andrew

]]> bWlncmF0aW9uIHRlc3Q= - YourCompany2012.doc YourCompany2012.doc crm.lead diff --git a/addons/hr_recruitment/data/hr_recruitment_demo.xml b/addons/hr_recruitment/data/hr_recruitment_demo.xml index bd1bbdc00a8..1f33e71cc0a 100644 --- a/addons/hr_recruitment/data/hr_recruitment_demo.xml +++ b/addons/hr_recruitment/data/hr_recruitment_demo.xml @@ -234,21 +234,18 @@ Jones_CV.pdf - Jones_CV.pdf hr.applicant Jose_CV.txt - Jose_CV.txt hr.applicant Williams_CV.doc - Williams_CV.doc hr.applicant diff --git a/addons/hr_recruitment/tests/test_recruitment_process.py b/addons/hr_recruitment/tests/test_recruitment_process.py index 322e6c0d938..c840b4e2670 100644 --- a/addons/hr_recruitment/tests/test_recruitment_process.py +++ b/addons/hr_recruitment/tests/test_recruitment_process.py @@ -30,7 +30,7 @@ class TestRecruitmentProcess(common.TransactionCase): applicant = self.env['hr.applicant'].search([('email_from', '=', 'Mr. Richard Anderson ')], limit=1) self.assertTrue(applicant, "Applicant is not created after getting the mail") resume_ids = self.env['ir.attachment'].search([ - ('datas_fname', '=', 'resume.pdf'), + ('name', '=', 'resume.pdf'), ('res_model', '=', self.env['hr.applicant']._name), ('res_id', '=', applicant.id)]) self.assertEquals(applicant.name, 'Application for the post of Jr.application Programmer.', 'Applicant name does not match.') diff --git a/addons/l10n_be_edi/models/account_invoice.py b/addons/l10n_be_edi/models/account_invoice.py index 642d44acd49..8f54e6d8381 100644 --- a/addons/l10n_be_edi/models/account_invoice.py +++ b/addons/l10n_be_edi/models/account_invoice.py @@ -119,7 +119,6 @@ class AccountInvoice(models.Model): 'res_id': self.id, 'res_model': 'account.invoice', 'datas': attachment_data, - 'datas_fname': attachment_name, 'type': 'binary', }) self.with_context(no_new_invoice=True).message_post(attachment_ids=[attachment_id.id]) diff --git a/addons/l10n_be_edi/tests/test_ubl.py b/addons/l10n_be_edi/tests/test_ubl.py index 83330dec590..c307595281a 100644 --- a/addons/l10n_be_edi/tests/test_ubl.py +++ b/addons/l10n_be_edi/tests/test_ubl.py @@ -20,7 +20,6 @@ class TestUBL(common.TransactionCase): attachment_id = self.env['ir.attachment'].create({ 'name': 'efff_test.xml', - 'datas_fname': 'efff_test.xml', 'datas': base64.encodestring(xml_file), 'res_id': invoice_id.id, 'res_model': 'account.invoice', diff --git a/addons/l10n_generic_coa/data/account_invoice_demo.xml b/addons/l10n_generic_coa/data/account_invoice_demo.xml index 55828f6870f..7d35455cd3f 100644 --- a/addons/l10n_generic_coa/data/account_invoice_demo.xml +++ b/addons/l10n_generic_coa/data/account_invoice_demo.xml @@ -139,10 +139,9 @@ in_invoice - in_invoice_pdf binary - in_invoice_yourcompany_demo.pdf + in_invoice_yourcompany_demo.pdf account.invoice diff --git a/addons/l10n_it_edi/models/account_invoice.py b/addons/l10n_it_edi/models/account_invoice.py index b1a7072eb22..7ec425fe5bb 100644 --- a/addons/l10n_it_edi/models/account_invoice.py +++ b/addons/l10n_it_edi/models/account_invoice.py @@ -163,7 +163,6 @@ class AccountInvoice(models.Model): 'res_id': invoice.id, 'res_model': invoice._name, 'datas': base64.encodestring(data), - 'datas_fname': report_name, 'description': description, 'type': 'binary', }) @@ -660,7 +659,6 @@ class AccountInvoice(models.Model): attachment_64 = self.env['ir.attachment'].create({ 'name': name_attachment, 'datas': attachment_64, - 'datas_fname': name_attachment, 'type': 'binary', }) diff --git a/addons/l10n_it_edi/models/ir_mail_server.py b/addons/l10n_it_edi/models/ir_mail_server.py index 3bfce47100d..3b16d7a3076 100644 --- a/addons/l10n_it_edi/models/ir_mail_server.py +++ b/addons/l10n_it_edi/models/ir_mail_server.py @@ -135,7 +135,6 @@ class FetchmailServer(models.Model): invoice_attachment = self.env['ir.attachment'].create({ 'name': att_name, 'datas': base64.encodestring(att_content), - 'datas_fname': att_name, 'type': 'binary', }) diff --git a/addons/mail/data/mail_demo.xml b/addons/mail/data/mail_demo.xml index b4e7f2c092e..3cfb89792ae 100644 --- a/addons/mail/data/mail_demo.xml +++ b/addons/mail/data/mail_demo.xml @@ -41,12 +41,10 @@ virginie@agrolait.fr bWlncmF0aW9uIHRlc3Q= - catalog.doc catalog.doc - activity_graph_2012.jpg - activity_graph_2012 + activity_graph_2012.jpg @@ -82,12 +80,10 @@ virginie@agrolait.fr bWlncmF0aW9uIHRlc3Q= - RedHat_spec.doc RedHat_spec.doc bWlncmF0aW9uIHRlc3Q= - RedHat_spec_draft_v3.doc RedHat_spec_draft_v3.doc diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index ffc8aa33399..3b575b08405 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -294,8 +294,8 @@ class MailMail(models.Model): # load attachment binary data with a separate read(), as prefetching all # `datas` (binary field) could bloat the browse cache, triggerring # soft/hard mem limits with temporary data. - attachments = [(a['datas_fname'], base64.b64decode(a['datas']), a['mimetype']) - for a in attachments.sudo().read(['datas_fname', 'datas', 'mimetype'])] + attachments = [(a['name'], base64.b64decode(a['datas']), a['mimetype']) + for a in attachments.sudo().read(['name', 'datas', 'mimetype'])] # specific behavior to customize the send email for notified partners email_list = [] diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index e1fc850d433..2fab423412b 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -336,11 +336,11 @@ class Message(models.Model): partner_tree = dict((partner[0], partner) for partner in partners_names) # 2. Attachments as SUPERUSER, because could receive msg and attachments for doc uid cannot see - attachments_data = attachments.sudo().read(['id', 'datas_fname', 'name', 'mimetype']) + attachments_data = attachments.sudo().read(['id', 'name', 'mimetype']) safari = request and request.httprequest.user_agent.browser == 'safari' attachments_tree = dict((attachment['id'], { 'id': attachment['id'], - 'filename': attachment['datas_fname'], + 'filename': attachment['name'], 'name': attachment['name'], 'mimetype': 'application/octet-stream' if safari and attachment['mimetype'] and 'video' in attachment['mimetype'] else attachment['mimetype'], }) for attachment in attachments_data) @@ -1035,7 +1035,6 @@ class Message(models.Model): attachment = Attachments.create({ 'name': name, 'datas': match.group(2), - 'datas_fname': name, 'res_model': values.get('model'), 'res_id': values.get('res_id'), }) diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 0ced62009dd..c2f601003d7 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -549,7 +549,6 @@ class MailTemplate(models.Model): for attachment in attachments: attachment_data = { 'name': attachment[0], - 'datas_fname': attachment[0], 'datas': attachment[1], 'type': 'binary', 'res_model': 'mail.message', diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 17d6941377b..e419c5430b8 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1633,7 +1633,6 @@ class MailThread(models.AbstractModel): 'name': name, 'datas': base64.b64encode(content), 'type': 'binary', - 'datas_fname': name, 'description': name, 'res_model': model, 'res_id': res_id, diff --git a/addons/mail/static/src/js/attachment_box.js b/addons/mail/static/src/js/attachment_box.js index f58c64f26e7..cc5d53ee1c0 100644 --- a/addons/mail/static/src/js/attachment_box.js +++ b/addons/mail/static/src/js/attachment_box.js @@ -36,7 +36,7 @@ var AttachmentBox = Widget.extend({ _.each(attachments, function (attachment) { // required for compatibility with the chatter templates. attachment.url = '/web/content/' + attachment.id + '?download=true'; - attachment.filename = attachment.datas_fname || 'unnamed'; + attachment.filename = attachment.name || 'unnamed'; }); var sortedAttachments = _.partition(attachments, function (att) { return att.mimetype && att.mimetype.split('/')[0] === 'image'; diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js index 6cd159c5ad3..f81bcb2d0e2 100644 --- a/addons/mail/static/src/js/chatter.js +++ b/addons/mail/static/src/js/chatter.js @@ -258,7 +258,7 @@ var Chatter = Widget.extend({ model: 'ir.attachment', method: 'search_read', domain: domain, - fields: ['id', 'name', 'datas_fname', 'mimetype'], + fields: ['id', 'name', 'mimetype'], }).then(function (result) { self._areAttachmentsLoaded = true; self.attachments = result; diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index 82772d5f3a1..91b9a28661e 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -170,15 +170,14 @@ QUnit.module('Chatter', { url:{type:'char', string:'url'}, type:{ type:'selection', selection:[['url',"URL"],['binary',"BINARY"]]}, mimetype:{type:'char', string:"mimetype"}, - datas_fname:{type:'char', string:"filename"}, }, records:[ - {id:1, name:"name1", type:'url', mimetype:'image/png', datas_fname:'filename.jpg', + {id:1, type:'url', mimetype:'image/png', name:'filename.jpg', res_id: 7, res_model: 'partner'}, - {id:2, name:"name2", type:'binary', mimetype:"application/x-msdos-program", - datas_fname:"file2.txt", res_id: 7, res_model: 'partner'}, - {id:3, name:"name2", type:'binary', mimetype:"application/x-msdos-program", - datas_fname:"file2.txt", res_id: 5, res_model: 'partner'}, + {id:2, type:'binary', mimetype:"application/x-msdos-program", + name:"file2.txt", res_id: 7, res_model: 'partner'}, + {id:3, type:'binary', mimetype:"application/x-msdos-program", + name:"file3.txt", res_id: 5, res_model: 'partner'}, ], }, }; @@ -321,10 +320,9 @@ QUnit.test('Activity Done by uploading a file', async function (assert) { $(window).trigger(fileuploadID, [{ id:3, - name:"name2", type:'binary', mimetype:"application/x-msdos-program", - datas_fname:"file2.txt", + name:"file2.txt", res_id: 5, res_model: 'partner' }]); @@ -438,12 +436,12 @@ QUnit.test('attachmentBox basic rendering', async function (assert) { assert.hasAttrValue($resIdInput, 'value', '7'); assert.hasAttrValue($resIdInput, 'type', 'hidden'); - assert.strictEqual(form.$('.o_attachment_title').text(), 'name1', + assert.strictEqual(form.$('.o_attachment_title').text(), 'filename.jpg', "the image name should be correct"); // since there are two elements "Download name2"; one "name" and the other "txt" as text content, the following test // asserts both at the same time. - assert.strictEqual(form.$('a[title = "Download name2"]').text().trim(), 'name2txt', - "the attachment name should be correct"); + assert.strictEqual(form.$('a[title = "Download file2.txt"]').text().trim(), 'file2.txttxt', + "the attachment name and the extension display should be correct"); assert.ok(form.$('.o_attachment_image').css('background-image').indexOf('/web/image/1/160x160/?crop=true') >= 0, "the attachment image URL should be correct"); assert.hasAttrValue(form.$('.o_attachment_download').eq(0), 'href', '/web/content/1?download=true', diff --git a/addons/mail/static/tests/document_viewer_tests.js b/addons/mail/static/tests/document_viewer_tests.js index b5748ab72ee..404a6f267aa 100644 --- a/addons/mail/static/tests/document_viewer_tests.js +++ b/addons/mail/static/tests/document_viewer_tests.js @@ -65,12 +65,12 @@ var createViewer = function (params) { QUnit.module('DocumentViewer', { beforeEach: function () { this.attachments = [ - {id: 1, datas_fname: 'filePdf.pdf', type: 'binary', mimetype: 'application/pdf', datas:'R0lGOP////ywAADs='}, - {id: 2, name: 'urlYoutubeName', type: 'url', mimetype: '', url: 'https://youtu.be/FYqW0Gdwbzk', datas_fname: 'urlYoutube'}, - {id: 3, name: 'urlGoogle', type: 'url', mimetype: '', url: 'https://www.google.com', datas_fname: 'urlRandom'}, - {id: 4, name: 'text.html', datas_fname: 'text.html', type: 'binary', mimetype: 'text/html', datas:'testee'}, - {id: 5, name: 'video.mp4', datas_fname: 'video.mp4', type: 'binary', mimetype: 'video/mp4', datas:'R0lDOP////ywAADs='}, - {id: 6, name: 'image.jpg', datas_fname: 'image.jpg', type: 'binary', mimetype: 'image/jpeg', checksum: 999, datas:'R0lVOP////ywAADs='}, + {id: 1, name: 'filePdf.pdf', type: 'binary', mimetype: 'application/pdf', datas:'R0lGOP////ywAADs='}, + {id: 2, name: 'urlYoutube', type: 'url', mimetype: '', url: 'https://youtu.be/FYqW0Gdwbzk'}, + {id: 3, name: 'urlRandom', type: 'url', mimetype: '', url: 'https://www.google.com'}, + {id: 4, name: 'text.html', type: 'binary', mimetype: 'text/html', datas:'testee'}, + {id: 5, name: 'video.mp4', type: 'binary', mimetype: 'video/mp4', datas:'R0lDOP////ywAADs='}, + {id: 6, name: 'image.jpg', type: 'binary', mimetype: 'image/jpeg', checksum: 999, datas:'R0lVOP////ywAADs='}, ]; }, }, function () { @@ -116,7 +116,7 @@ QUnit.module('DocumentViewer', { }, }); - assert.strictEqual(viewer.$(".o_image_caption:contains('urlYoutubeName')").length, 1, + assert.strictEqual(viewer.$(".o_image_caption:contains('urlYoutube')").length, 1, "the viewer should be on the right attachment"); assert.containsOnce(viewer, '.o_viewer_text[data-src="' + youtubeURL + '"]', "there should be a video player"); diff --git a/addons/mail/views/mail_message_views.xml b/addons/mail/views/mail_message_views.xml index df7643f7f36..b7ae76d8272 100644 --- a/addons/mail/views/mail_message_views.xml +++ b/addons/mail/views/mail_message_views.xml @@ -139,7 +139,6 @@ - @@ -159,13 +158,8 @@
-
- - - - - - +
+
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 1d54406b086..ba65f787257 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -415,7 +415,6 @@ class MailComposer(models.TransientModel): data_attach = { 'name': attach_fname, 'datas': attach_datas, - 'datas_fname': attach_fname, 'res_model': 'mail.compose.message', 'res_id': 0, 'type': 'binary', # override default_type from context, possibly meant for another model! diff --git a/addons/mass_mailing/data/mass_mailing_demo.xml b/addons/mass_mailing/data/mass_mailing_demo.xml index e9df5daaa35..c1fdc2483f2 100644 --- a/addons/mass_mailing/data/mass_mailing_demo.xml +++ b/addons/mass_mailing/data/mass_mailing_demo.xml @@ -4,7 +4,6 @@ bWlncmF0aW9uIHRlc3Q= - SampleDoc.doc SampleDoc.doc diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py index 6d47d33e356..b4cdf4109fc 100644 --- a/addons/mass_mailing/models/mass_mailing.py +++ b/addons/mass_mailing/models/mass_mailing.py @@ -704,9 +704,8 @@ class MassMailing(models.Model): def _image_to_url(b64image: bytes): """Store an image in an attachement and returns an url""" attachment = self.env['ir.attachment'].create({ - 'name': "cropped_image", 'datas': b64image, - 'datas_fname': "cropped_image_mailing_{}".format(self.id), + 'name': "cropped_image_mailing_{}".format(self.id), 'type': 'binary',}) attachment.generate_access_token() diff --git a/addons/mrp/views/ir_attachment_view.xml b/addons/mrp/views/ir_attachment_view.xml index d0657d6b28f..415ae3a5233 100644 --- a/addons/mrp/views/ir_attachment_view.xml +++ b/addons/mrp/views/ir_attachment_view.xml @@ -9,7 +9,6 @@ - @@ -30,7 +29,7 @@
- +
diff --git a/addons/snailmail/models/snailmail_letter.py b/addons/snailmail/models/snailmail_letter.py index 797bf92a0b0..a0925515a2c 100644 --- a/addons/snailmail/models/snailmail_letter.py +++ b/addons/snailmail/models/snailmail_letter.py @@ -37,7 +37,7 @@ class SnailmailLetter(models.Model): attachment_id = fields.Many2one('ir.attachment', string='Attachment', ondelete='cascade') attachment_datas = fields.Binary('Document', related='attachment_id.datas') - attachment_fname = fields.Char('Attachment Filename', related='attachment_id.datas_fname') + attachment_fname = fields.Char('Attachment Filename', related='attachment_id.name') color = fields.Boolean(string='Color', default=lambda self: self.env.company.snailmail_color) cover = fields.Boolean(string='Cover Page', default=lambda self: self.env.company.snailmail_cover) duplex = fields.Boolean(string='Both side', default=lambda self: self.env.company.snailmail_duplex) @@ -125,7 +125,6 @@ class SnailmailLetter(models.Model): attachment = self.env['ir.attachment'].create({ 'name': filename, 'datas': base64.b64encode(pdf_bin), - 'datas_fname': filename, 'res_model': 'snailmail.letter', 'res_id': self.id, 'type': 'binary', # override default_type from context, possibly meant for another model! diff --git a/addons/test_mail/tests/test_mail_message.py b/addons/test_mail/tests/test_mail_message.py index c13fe2626ca..4f777ff8b7e 100644 --- a/addons/test_mail/tests/test_mail_message.py +++ b/addons/test_mail/tests/test_mail_message.py @@ -237,8 +237,7 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails): def test_mail_message_access_read_notification(self): attachment = self.env['ir.attachment'].create({ 'datas': base64.b64encode(b'My attachment'), - 'name': 'doc.txt', - 'datas_fname': 'doc.txt'}) + 'name': 'doc.txt'}) # attach the attachment to the message self.message.write({'attachment_ids': [(4, attachment.id)]}) self.message.write({'partner_ids': [(4, self.user_employee.partner_id.id)]}) diff --git a/addons/test_mail/tests/test_mail_template.py b/addons/test_mail/tests/test_mail_template.py index 86327c174d4..ebff4b24a3a 100644 --- a/addons/test_mail/tests/test_mail_template.py +++ b/addons/test_mail/tests/test_mail_template.py @@ -20,14 +20,12 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients): }) self._attachments = [{ - 'name': '_Test_First', - 'datas_fname': 'first.txt', + 'name': 'first.txt', 'datas': base64.b64encode(b'My first attachment'), 'res_model': 'res.partner', 'res_id': self.user_admin.partner_id.id }, { - 'name': '_Test_Second', - 'datas_fname': 'second.txt', + 'name': 'second.txt', 'datas': base64.b64encode(b'My second attachment'), 'res_model': 'res.partner', 'res_id': self.user_admin.partner_id.id diff --git a/addons/test_mail/tests/test_message_compose.py b/addons/test_mail/tests/test_message_compose.py index 32a9a44e3ee..f755213a93f 100644 --- a/addons/test_mail/tests/test_message_compose.py +++ b/addons/test_mail/tests/test_message_compose.py @@ -86,11 +86,11 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients): ('List2', b'My second attachment') ] _attach_1 = self.env['ir.attachment'].sudo(self.user_employee).create({ - 'name': 'Attach1', 'datas_fname': 'Attach1', + 'name': 'Attach1', 'datas': 'bWlncmF0aW9uIHRlc3Q=', 'res_model': 'mail.compose.message', 'res_id': 0}) _attach_2 = self.env['ir.attachment'].sudo(self.user_employee).create({ - 'name': 'Attach2', 'datas_fname': 'Attach2', + 'name': 'Attach2', 'datas': 'bWlncmF0aW9uIHRlc3Q=', 'res_model': 'mail.compose.message', 'res_id': 0}) diff --git a/addons/test_mail/tests/test_odoobot.py b/addons/test_mail/tests/test_odoobot.py index 900e7b62689..76a45eb73f7 100644 --- a/addons/test_mail/tests/test_odoobot.py +++ b/addons/test_mail/tests/test_odoobot.py @@ -63,7 +63,6 @@ class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients): kwargs['body'] = '' attachment = self.env['ir.attachment'].sudo(self.user_employee).create({ 'datas': 'bWlncmF0aW9uIHRlc3Q=', - 'datas_fname': 'catalog.doc', 'name': 'picture_of_your_dog.doc', }) kwargs['attachment_ids'] = [attachment.id] diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index cb2300a6df3..de2e4321cc9 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -728,8 +728,7 @@ class TestMailPerformancePost(TransactionCase): }) self.vals = [{ 'datas': base64.b64encode(bytes("attachement content %s" % i, 'utf-8')), - 'name': 'attach %s' % i, - 'datas_fname': 'fileText_test%s.txt' % i, + 'name': 'fileText_test%s.txt' % i, 'mimetype': 'text/plain', 'res_model': 'mail.compose.message', 'res_id': 0, diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 1b16c64cd4d..fe4ded3bb71 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1009,7 +1009,7 @@ class Binary(http.Controller): '/web/content///', '/web/content////'], type='http', auth="public") def content_common(self, xmlid=None, model='ir.attachment', id=None, field='datas', - filename=None, filename_field='datas_fname', unique=None, mimetype=None, + filename=None, filename_field='name', unique=None, mimetype=None, download=None, data=None, token=None, access_token=None, **kw): status, headers, content = request.env['ir.http'].binary_content( @@ -1053,7 +1053,7 @@ class Binary(http.Controller): '/web/image/-/x', '/web/image/-/x/'], type='http', auth="public") def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', - filename_field='datas_fname', unique=None, filename=None, mimetype=None, + filename_field='name', unique=None, filename=None, mimetype=None, download=None, width=0, height=0, crop=False, access_token=None, **kwargs): # other kwargs are ignored on purpose @@ -1063,7 +1063,7 @@ class Binary(http.Controller): quality=int(kwargs.get('quality', 0)), access_token=access_token) def _content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', - filename_field='datas_fname', unique=None, filename=None, mimetype=None, + filename_field='name', unique=None, filename=None, mimetype=None, download=None, width=0, height=0, crop=False, quality=0, access_token=None, placeholder='placeholder.png', **kwargs): status, headers, image_base64 = request.env['ir.http'].binary_content( @@ -1134,7 +1134,6 @@ class Binary(http.Controller): attachment = Model.create({ 'name': filename, 'datas': base64.encodestring(ufile.read()), - 'datas_fname': filename, 'res_model': model, 'res_id': int(id) }) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 398928f585b..325bb176e61 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1803,7 +1803,6 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ supportedFieldTypes: ['many2many'], fieldsToFetch: { name: {type: 'char'}, - datas_fname: {type: 'char'}, mimetype: {type: 'char'}, }, events: { diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index aec23c150bc..b5e098d230c 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2247,7 +2247,7 @@ QUnit.module('relational_fields', { mockRPC: function (route, args) { assert.step(route); if (route === '/web/dataset/call_kw/ir.attachment/read') { - assert.deepEqual(args.args[1], ['name', 'datas_fname', 'mimetype']); + assert.deepEqual(args.args[1], ['name', 'mimetype']); } return this._super.apply(this, arguments); }, diff --git a/addons/web_editor/models/assets.py b/addons/web_editor/models/assets.py index 72b1b557e90..4178335624c 100644 --- a/addons/web_editor/models/assets.py +++ b/addons/web_editor/models/assets.py @@ -173,11 +173,10 @@ class Assets(models.AbstractModel): # If not, create a new attachment to copy the original scss/js file # content, with its modifications new_attach = { - 'name': custom_url, + 'name': url.split("/")[-1], 'type': "binary", 'mimetype': (file_type == 'js' and 'text/javascript' or 'text/scss'), 'datas': datas, - 'datas_fname': url.split("/")[-1], 'url': custom_url, } new_attach.update(self._save_asset_attachment_hook()) diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/media.js b/addons/web_editor/static/src/js/wysiwyg/plugin/media.js index 8ff6a100627..b11c15b2564 100644 --- a/addons/web_editor/static/src/js/wysiwyg/plugin/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/plugin/media.js @@ -800,7 +800,6 @@ var ImagePlugin = AbstractMediaPlugin.extend({ res_model: resModel, res_id: resID, name: name, - datas_fname: name, datas: datas, mimetype: mimetype, url: originalSrc, // To save the original image that was cropped diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index 3303ec0a58f..545f06a38e2 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -233,13 +233,13 @@ var FileWidget = SearchableMediaWidget.extend({ .sortBy(function (r) { if (_.any(self.options.firstFilters, function (filter) { var regex = new RegExp(filter, 'i'); - return r.name.match(regex) || r.name && r.name.match(regex); + return r.name && r.name.match(regex); })) { return -1; } if (_.any(self.options.lastFilters, function (filter) { var regex = new RegExp(filter, 'i'); - return r.name.match(regex) || r.name && r.name.match(regex); + return r.name && r.name.match(regex); })) { return 1; } @@ -323,9 +323,9 @@ var FileWidget = SearchableMediaWidget.extend({ domain = ['|', ['public', '=', true]].concat(domain); domain = domain.concat(this.options.mimetypeDomain); if (needle && needle.length) { - domain.push('|', ['name', 'ilike', needle], ['name', 'ilike', needle]); + domain.push(['name', 'ilike', needle]); } - domain.push('|', ['name', '=', false], '!', ['name', '=like', '%.crop'], '!', ['name', '=like', '%.crop']); + domain.push('!', ['name', '=like', '%.crop']); domain.push('|', ['type', '=', 'binary'], ['url', '!=', false]); return domain; }, diff --git a/addons/web_editor/static/tests/test_utils.js b/addons/web_editor/static/tests/test_utils.js index 0501baee4ea..99510bb3bae 100644 --- a/addons/web_editor/static/tests/test_utils.js +++ b/addons/web_editor/static/tests/test_utils.js @@ -319,10 +319,6 @@ function wysiwygData(data) { string: "display_name", type: 'char', }, - datas_fname: { - string: "datas_fname", - type: 'char', - }, mimetype: { string: "mimetype", type: 'char', @@ -371,7 +367,6 @@ function wysiwygData(data) { records: [{ id: 1, name: 'image', - datas_fname: 'image.png', mimetype: 'image/png', checksum: false, url: '/web_editor/static/src/img/transparent.png', diff --git a/addons/web_unsplash/controllers/main.py b/addons/web_unsplash/controllers/main.py index 98b3cec976e..f3a1c91dab9 100644 --- a/addons/web_unsplash/controllers/main.py +++ b/addons/web_unsplash/controllers/main.py @@ -106,9 +106,8 @@ class Web_Unsplash(http.Controller): url_frags = ['unsplash', key, query] attachment = Attachments.create({ - 'name': query, + 'name': '_'.join(url_frags), 'url': '/' + '/'.join(url_frags), - 'datas_fname': '_'.join(url_frags), 'mimetype': mimetype, 'datas': image_base64, 'public': res_model == 'ir.ui.view', diff --git a/addons/website/data/website_data.xml b/addons/website/data/website_data.xml index 737ff819de8..1d50c7bf704 100644 --- a/addons/website/data/website_data.xml +++ b/addons/website/data/website_data.xml @@ -173,136 +173,119 @@ - business_conference - business_conference.jpg + business_conference.jpg ir.ui.view binary - Website Library Image 01 - bridge.jpg + bridge.jpg ir.ui.view url /website/static/src/img/library/bridge.jpg - Website Library Image 02 - deliver.jpg + deliver.jpg ir.ui.view url /website/static/src/img/library/deliver.jpg - Website Library Image 03 - clock.jpg + clock.jpg ir.ui.view url /website/static/src/img/library/clock.jpg - Website Library Image 04 - manufacturing.jpg + manufacturing.jpg ir.ui.view url /website/static/src/img/library/manufacturing.jpg - Website Library Image 05 - compass.jpg + compass.jpg ir.ui.view url /website/static/src/img/library/compass.jpg - Website Library Image 06 - gift.jpg + gift.jpg ir.ui.view url /website/static/src/img/library/gift.jpg - Website Library Image 07 - mobile_device.jpg + mobile_device.jpg ir.ui.view url /website/static/src/img/library/mobile_device.jpg - Website Library Image 08 - mobile.jpg + mobile.jpg ir.ui.view url /website/static/src/img/library/mobile.jpg - Website Library Image 09 - office.jpg + office.jpg ir.ui.view url /website/static/src/img/library/office.jpg - Website Library Image 10 - ice_coffe.jpg + ice_coffe.jpg ir.ui.view url /website/static/src/img/library/ice_coffe.jpg - Website Library Image 11 - rocket.jpg + rocket.jpg ir.ui.view url /website/static/src/img/library/rocket.jpg - Website Library Image 12 - sell.jpg + sell.jpg ir.ui.view url /website/static/src/img/library/sell.jpg - Website Library Image 13 - shop.jpg + shop.jpg ir.ui.view url /website/static/src/img/library/shop.jpg - Website Library Image 14 - sign.jpg + sign.jpg ir.ui.view url /website/static/src/img/library/sign.jpg - Website Library Image 15 - sweet.jpg + sweet.jpg ir.ui.view url /website/static/src/img/library/sweet.jpg - Website Library Image 16 - wine.jpg + wine.jpg ir.ui.view url /website/static/src/img/library/wine.jpg @@ -311,72 +294,63 @@ - Website Background Image 01 - s_background_image_01.jpg + s_background_image_01.jpg url ir.ui.view /website/static/src/img/backgrounds/peak.jpg - Website Background Image 02 - s_background_image_02.jpg + s_background_image_02.jpg url ir.ui.view /website/static/src/img/backgrounds/la.jpg - Website Background Image 03 - s_background_image_03.jpg + s_background_image_03.jpg url ir.ui.view /website/static/src/img/backgrounds/panama-sky.jpg - Website Background Image 04 - s_background_image_04.jpg + s_background_image_04.jpg url ir.ui.view /website/static/src/img/backgrounds/cubes.jpg - Website Background Image 05 - s_background_image_05.jpg + s_background_image_05.jpg url ir.ui.view /website/static/src/img/backgrounds/building-profile.jpg - Website Background Image 06 - s_background_image_06.jpg + s_background_image_06.jpg url ir.ui.view /website/static/src/img/backgrounds/type.jpg - Website Background Image 07 - s_background_image_07.jpg + s_background_image_07.jpg url ir.ui.view /website/static/src/img/backgrounds/people.jpg - Website Background Image 08 - s_background_image_08.jpg + s_background_image_08.jpg url ir.ui.view /website/static/src/img/backgrounds/city.jpg - Website Background Image 09 - s_background_image_09.jpg + s_background_image_09.jpg url ir.ui.view /website/static/src/img/backgrounds/sails.jpg @@ -385,162 +359,139 @@ - Cover Snippet - Default Image - s_cover_default_image.jpg + s_cover_default_image.jpg url /website/static/src/img/snippets_demo/s_cover.jpg - Quotes Carousel Snippet - Demo Image 1 - s_quotes_carousel_image_01.jpg + s_quotes_carousel_image_01.jpg url /website/static/src/img/snippets_demo/s_quotes_carousel_1.jpg - Quotes Carousel Snippet - Demo Image 2 - s_quotes_carousel_image_02.jpg + s_quotes_carousel_image_02.jpg url /website/static/src/img/snippets_demo/s_quotes_carousel_2.jpg - Quotes Carousel Snippet - Demo Image 3 - s_quotes_carousel_image_3.png + s_quotes_carousel_image_3.png url /website/static/src/img/snippets_demo/s_team_member_3.png - Quotes Carousel Snippet - Demo Image 4 - s_quotes_carousel_image_4.png + s_quotes_carousel_image_4.png url /website/static/src/img/snippets_demo/s_team_member_2.png - Quotes Carousel Snippet - Demo Image 5 - s_quotes_carousel_image_5.png + s_quotes_carousel_image_5.png url /website/static/src/img/snippets_demo/s_team_member_4.png - Image Text Snippet - Default Image - s_image_text_default_image.jpg + s_image_text_default_image.jpg url /website/static/src/img/snippets_demo/s_image_text.jpg - Text Image Snippet - Default Image - s_text_image_default_image.jpg + s_text_image_default_image.jpg url /website/static/src/img/snippets_demo/s_text_image.jpg - Carousel Snippet - Default Image 1 - s_carousel_default_image_1.jpg + s_carousel_default_image_1.jpg url /website/static/src/img/snippets_demo/s_carousel_1.jpg - Carousel Snippet - Default Image 2 - s_carousel_default_image_2.jpg + s_carousel_default_image_2.jpg url /website/static/src/img/snippets_demo/s_carousel_2.jpg - Carousel Snippet - Default Image 3 - s_carousel_default_image_3.jpg + s_carousel_default_image_3.jpg url /website/static/src/img/snippets_demo/s_carousel_3.jpg - Picture Snippet - Default Image - s_picture_default_image.jpg + s_picture_default_image.jpg url /website/static/src/img/snippets_demo/s_picture.jpg - Banner Snippet - Default Image - s_banner_default_image.jpg + s_banner_default_image.jpg url /website/static/src/img/snippets_demo/s_banner.jpg - Parallax Snippet - Default Image - s_parallax_default_image.jpg + s_parallax_default_image.jpg url /website/static/src/img/snippets_demo/s_parallax.jpg - Reference Snippet - Demo Image 1 - s_reference_demo_image_1.png + s_reference_demo_image_1.png url /website/static/src/img/snippets_demo/s_references_1.png - Reference Snippet - Demo Image 2 - s_reference_demo_image_2.png + s_reference_demo_image_2.png url /website/static/src/img/snippets_demo/s_references_2.png - Reference Snippet - Demo Image 3 - s_reference_demo_image_3.png + s_reference_demo_image_3.png url /website/static/src/img/snippets_demo/s_references_3.png - Reference Snippet - Demo Image 4 - s_reference_demo_image_4.png + s_reference_demo_image_4.png url /website/static/src/img/snippets_demo/s_references_4.png - Reference Snippet - Demo Image 5 - s_reference_demo_image_5.png + s_reference_demo_image_5.png url /website/static/src/img/snippets_demo/s_references_5.png - Company Team Snippet - Image 1 - s_company_team_image_1.png + s_company_team_image_1.png url /website/static/src/img/snippets_demo/s_team_member_1.png - Company Team Snippet - Image 2 - s_company_team_image_2.png + s_company_team_image_2.png url /website/static/src/img/snippets_demo/s_team_member_2.png - Company Team Snippet - Image 3 - s_company_team_image_3.png + s_company_team_image_3.png url /website/static/src/img/snippets_demo/s_team_member_3.png - Company Team Snippet - Image 4 - s_company_team_image_4.png + s_company_team_image_4.png url /website/static/src/img/snippets_demo/s_team_member_4.png diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 22f2dce7c4a..e6eb9c10fa9 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -287,7 +287,7 @@ class Http(models.AbstractModel): return werkzeug.wrappers.Response(html, status=code, content_type='text/html;charset=utf-8') def binary_content(self, xmlid=None, model='ir.attachment', id=None, field='datas', - unique=False, filename=None, filename_field='datas_fname', download=False, + unique=False, filename=None, filename_field='name', download=False, mimetype=None, default_mimetype='application/octet-stream', access_token=None): obj = None diff --git a/addons/website/static/src/js/editor/wysiwyg_multizone.js b/addons/website/static/src/js/editor/wysiwyg_multizone.js index 4509816c30e..201cbd64d21 100644 --- a/addons/website/static/src/js/editor/wysiwyg_multizone.js +++ b/addons/website/static/src/js/editor/wysiwyg_multizone.js @@ -434,7 +434,6 @@ var WysiwygMultizone = Wysiwyg.extend({ res_model: resModel, res_id: resID, name: name, - datas_fname: name, datas: datas, mimetype: mimetype, url: originalSrc, // To save the original image that was cropped diff --git a/addons/website/views/ir_attachment_views.xml b/addons/website/views/ir_attachment_views.xml index 19db9f670e8..f2ba6fccdc4 100644 --- a/addons/website/views/ir_attachment_views.xml +++ b/addons/website/views/ir_attachment_views.xml @@ -15,7 +15,7 @@ ir.attachment - + diff --git a/addons/website_blog/data/website_blog_data.xml b/addons/website_blog/data/website_blog_data.xml index 3438ae7a870..169cbc67ac7 100644 --- a/addons/website_blog/data/website_blog_data.xml +++ b/addons/website_blog/data/website_blog_data.xml @@ -17,7 +17,6 @@ Blog Post Cover 1 - Blog Post Cover 1 ir.ui.view url /website_blog/static/src/img/demo/blog_post_cover_1.jpg @@ -26,7 +25,6 @@ Blog Post Cover 2 - Blog Post Cover 2 ir.ui.view url /website_blog/static/src/img/demo/blog_post_cover_2.jpg diff --git a/addons/website_form/controllers/main.py b/addons/website_form/controllers/main.py index fc9c326eb07..1785766def7 100644 --- a/addons/website_form/controllers/main.py +++ b/addons/website_form/controllers/main.py @@ -213,7 +213,6 @@ class WebsiteForm(http.Controller): attachment_value = { 'name': file.filename, 'datas': base64.encodestring(file.read()), - 'datas_fname': file.filename, 'res_model': model_name, 'res_id': record.id, } diff --git a/addons/website_sale_digital/data/product_demo.xml b/addons/website_sale_digital/data/product_demo.xml index b7497e04063..2388f15a023 100644 --- a/addons/website_sale_digital/data/product_demo.xml +++ b/addons/website_sale_digital/data/product_demo.xml @@ -13,7 +13,6 @@ ebook.pdf - ebook.pdf binary diff --git a/addons/website_theme_install/models/ir_module_module.py b/addons/website_theme_install/models/ir_module_module.py index e1b7489f7c5..e7e31e176f2 100644 --- a/addons/website_theme_install/models/ir_module_module.py +++ b/addons/website_theme_install/models/ir_module_module.py @@ -419,7 +419,6 @@ class IrModuleModule(models.Model): IrAttachment.create({ 'type': 'url', 'name': image_name, - 'datas_fname': image_name, 'url': image_path, 'res_model': self._name, 'res_id': app.id, diff --git a/addons/website_theme_install/models/theme_models.py b/addons/website_theme_install/models/theme_models.py index d36bee8a53a..b9b2f006c94 100644 --- a/addons/website_theme_install/models/theme_models.py +++ b/addons/website_theme_install/models/theme_models.py @@ -69,7 +69,6 @@ class ThemeAttachment(models.Model): url = fields.Char() copy_ids = fields.One2many('ir.attachment', 'theme_template_id', 'Attachment using a copy of me', copy=False, readonly=True) - # TODO in master: add missing field: datas_fname @api.multi def _convert_to_base_model(self, website, **kwargs): diff --git a/odoo/addons/base/models/assetsbundle.py b/odoo/addons/base/models/assetsbundle.py index 04e85944c0e..4afc9a76a56 100644 --- a/odoo/addons/base/models/assetsbundle.py +++ b/odoo/addons/base/models/assetsbundle.py @@ -262,8 +262,8 @@ class AssetsBundle(object): FROM ir_attachment WHERE create_uid = %s AND url like %s - GROUP BY datas_fname - ORDER BY datas_fname + GROUP BY name + ORDER BY name """, [SUPERUSER_ID, url_pattern]) attachment_ids = [r[0] for r in self.env.cr.fetchall()] return self.env['ir.attachment'].sudo().browse(attachment_ids) @@ -279,8 +279,7 @@ class AssetsBundle(object): fname = '%s.%s' % (self.name, type) mimetype = 'application/javascript' if type == 'js' else 'text/css' values = { - 'name': "/web/content/%s" % type, - 'datas_fname': fname, + 'name': fname, 'mimetype': mimetype, 'res_model': 'ir.ui.view', 'res_id': False, @@ -299,7 +298,6 @@ class AssetsBundle(object): type='' ) values = { - 'name': url, 'url': url, } attachment.write(values) @@ -448,9 +446,8 @@ class AssetsBundle(object): datas=base64.b64encode(asset.content.encode('utf8')), mimetype='text/css', type='binary', - name=url, + name=fname, url=url, - datas_fname=fname, res_model=False, res_id=False, )) diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index 0d78ca6cb97..5c4b773d164 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -154,7 +154,7 @@ class IrActionsReport(models.Model): if not attachment_name: return None return self.env['ir.attachment'].search([ - ('datas_fname', '=', attachment_name), + ('name', '=', attachment_name), ('res_model', '=', self.model), ('res_id', '=', record.id) ], limit=1) @@ -175,7 +175,6 @@ class IrActionsReport(models.Model): attachment_vals = { 'name': attachment_name, 'datas': base64.encodestring(buffer.getvalue()), - 'datas_fname': attachment_name, 'res_model': self.model, 'res_id': record.id, } diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index ce98ee7c296..3b314c7d849 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -201,7 +201,7 @@ class IrAttachment(models.Model): vals = { 'file_size': len(bin_data), 'checksum': self._compute_checksum(bin_data), - 'index_content': self._index(bin_data, attach.datas_fname, attach.mimetype), + 'index_content': self._index(bin_data, attach.mimetype), 'store_fname': False, 'db_datas': value, } @@ -232,8 +232,8 @@ class IrAttachment(models.Model): mimetype = None if values.get('mimetype'): mimetype = values['mimetype'] - if not mimetype and values.get('datas_fname'): - mimetype = mimetypes.guess_type(values['datas_fname'])[0] + if not mimetype and values.get('name'): + mimetype = mimetypes.guess_type(values['name'])[0] if not mimetype and values.get('url'): mimetype = mimetypes.guess_type(values['url'])[0] if values.get('datas') and (not mimetype or mimetype == 'application/octet-stream'): @@ -251,8 +251,8 @@ class IrAttachment(models.Model): return values @api.model - def _index(self, bin_data, datas_fname, file_type): - """ compute the index content of the given filename, or binary data. + def _index(self, bin_data, file_type): + """ compute the index content of the given binary data. This is a python implementation of the unix command 'strings'. :param bin_data : datas in binary form :return index_content : string containing all the printable character of the binary data @@ -275,7 +275,6 @@ class IrAttachment(models.Model): return ['base.group_system'] name = fields.Char('Name', required=True) - datas_fname = fields.Char('Filename') description = fields.Text('Description') res_name = fields.Char('Resource Name', compute='_compute_res_name', store=True) res_model = fields.Char('Resource Model', readonly=True, help="The database object this attachment will be attached to.") @@ -374,7 +373,7 @@ class IrAttachment(models.Model): raise AccessError(_("Sorry, you are not allowed to access this document.")) def _read_group_allowed_fields(self): - return ['type', 'company_id', 'res_id', 'create_date', 'create_uid', 'res_name', 'name', 'mimetype', 'id', 'url', 'datas_fname', 'res_field', 'res_model'] + return ['type', 'company_id', 'res_id', 'create_date', 'create_uid', 'res_name', 'name', 'mimetype', 'id', 'url', 'res_field', 'res_model'] @api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index ac6ccbc9eac..c69c3c6a12d 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -338,7 +338,7 @@ class IrHttp(models.AbstractModel): def _binary_record_content( self, record, field='datas', filename=None, - filename_field='datas_fname', default_mimetype='application/octet-stream'): + filename_field='name', default_mimetype='application/octet-stream'): model = record._name mimetype = 'mimetype' in record and record.mimetype or False @@ -387,7 +387,7 @@ class IrHttp(models.AbstractModel): return (status, headers, content) def binary_content(self, xmlid=None, model='ir.attachment', id=None, field='datas', - unique=False, filename=None, filename_field='datas_fname', download=False, + unique=False, filename=None, filename_field='name', download=False, mimetype=None, default_mimetype='application/octet-stream', access_token=None): """ Get file, attachment or downloadable content diff --git a/odoo/addons/base/tests/test_ir_http.py b/odoo/addons/base/tests/test_ir_http.py index 09efa81bd51..a5b0b88a3df 100644 --- a/odoo/addons/base/tests/test_ir_http.py +++ b/odoo/addons/base/tests/test_ir_http.py @@ -12,8 +12,7 @@ class test_ir_http_mimetype(common.TransactionCase): """ Test mimetype for attachment """ attachment = self.env['ir.attachment'].create({ 'datas': GIF, - 'name': 'Test mimetype gif', - 'datas_fname': 'file.gif'}) + 'name': 'file.gif'}) status, headers, content = self.env['ir.http'].binary_content( id=attachment.id, @@ -27,8 +26,7 @@ class test_ir_http_mimetype(common.TransactionCase): """ Test mimetype for attachment with bad name""" attachment = self.env['ir.attachment'].create({ 'datas': GIF, - 'name': 'Test mimetype gif with png name', - 'datas_fname': 'file.png'}) + 'name': 'file.png'}) status, headers, content = self.env['ir.http'].binary_content( id=attachment.id, @@ -81,8 +79,7 @@ class test_ir_http_mimetype(common.TransactionCase): public_user = self.env.ref('base.public_user') attachment = self.env['ir.attachment'].create({ 'datas': GIF, - 'name': 'Test valid access token with image', - 'datas_fname': 'image.gif' + 'name': 'image.gif' }) defaults = { diff --git a/odoo/addons/base/views/ir_attachment_views.xml b/odoo/addons/base/views/ir_attachment_views.xml index 8077b18e335..ff7338c9d1b 100644 --- a/odoo/addons/base/views/ir_attachment_views.xml +++ b/odoo/addons/base/views/ir_attachment_views.xml @@ -13,8 +13,7 @@ - - + @@ -49,7 +48,6 @@ - @@ -64,7 +62,7 @@ ir.attachment - +