diff --git a/attachment_edit/README.rst b/attachment_edit/README.rst new file mode 100644 index 00000000..d5f657e3 --- /dev/null +++ b/attachment_edit/README.rst @@ -0,0 +1,62 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================ +Edit attachments +================ + +This module adds a button on the records' attachment dropdown that allows to +open the attachment's form in edit mode. This makes it convenient to edit the +attachment's properties after upload. + +On the attachment's form, a field is added to move the attachment to another +record. + +Usage +===== + +Click the pencil that appears next to the delete button when you hover over +an attachment in order to edit it. + +To change the resource the attachment belongs to, edit the field `Resource +reference`. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/118/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/attachment_edit/__init__.py b/attachment_edit/__init__.py new file mode 100644 index 00000000..915f58d4 --- /dev/null +++ b/attachment_edit/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2015 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/attachment_edit/__openerp__.py b/attachment_edit/__openerp__.py new file mode 100644 index 00000000..cd5e14ae --- /dev/null +++ b/attachment_edit/__openerp__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# © 2015 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Edit attachments", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Knowledge Management", + "summary": "Edit attachments after upload", + "depends": [ + 'web', + ], + "data": [ + "views/ir_attachment.xml", + 'views/templates.xml', + ], + "qweb": [ + 'static/src/xml/attachment_edit.xml', + ], + "auto_install": False, + "installable": True, + "application": False, + "external_dependencies": { + 'python': [], + }, +} diff --git a/attachment_edit/models/__init__.py b/attachment_edit/models/__init__.py new file mode 100644 index 00000000..a0a80d1f --- /dev/null +++ b/attachment_edit/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2015 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import ir_attachment diff --git a/attachment_edit/models/ir_attachment.py b/attachment_edit/models/ir_attachment.py new file mode 100644 index 00000000..04da13b0 --- /dev/null +++ b/attachment_edit/models/ir_attachment.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# © 2015 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# -*- coding: utf-8 -*- +from openerp import models, fields, api + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + res_reference = fields.Reference( + selection='_selection_res_reference', + string='Resource reference', compute='_compute_res_reference', + inverse='_inverse_res_reference') + + @api.one + @api.depends('res_id', 'res_model') + def _compute_res_reference(self): + if self.res_model and self.res_id: + self.res_reference = '%s,%s' % (self.res_model, self.res_id) + + @api.one + def _inverse_res_reference(self): + if self.res_reference: + self.write({ + 'res_model': self.res_reference._model._model, + 'res_id': self.res_reference.id, + }) + else: + self.write({'res_model': False, 'res_id': False}) + + @api.model + def _selection_res_reference(self): + return self.env['ir.model'].search([ + ('osv_memory', '=', False), + ('access_ids.group_id.users', '=', self.env.uid) + ]).mapped(lambda rec: (rec.model, rec.name)) diff --git a/attachment_edit/static/description/icon.png b/attachment_edit/static/description/icon.png new file mode 100644 index 00000000..14d87f86 Binary files /dev/null and b/attachment_edit/static/description/icon.png differ diff --git a/attachment_edit/static/src/css/attachment_edit.css b/attachment_edit/static/src/css/attachment_edit.css new file mode 100644 index 00000000..3b25edd3 --- /dev/null +++ b/attachment_edit/static/src/css/attachment_edit.css @@ -0,0 +1,22 @@ +.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-edit +{ + position: absolute; + right: 32px; + top: 0px; + display: none; +} +.openerp .oe_sidebar .oe_dropdown_menu li:hover .oe-sidebar-attachment-edit +{ + display: inherit; +} +.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-edit:hover +{ + text-decoration: none; + color: white; + background: #8786b7; + text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4); + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + border-radius: 2px; +} + diff --git a/attachment_edit/static/src/js/attachment_edit.js b/attachment_edit/static/src/js/attachment_edit.js new file mode 100644 index 00000000..65234fd2 --- /dev/null +++ b/attachment_edit/static/src/js/attachment_edit.js @@ -0,0 +1,52 @@ +//-*- coding: utf-8 -*- +//############################################################################ +// +// OpenERP, Open Source Management Solution +// This module copyright (C) 2015 Therp BV . +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +//############################################################################ + +openerp.attachment_edit = function(instance) +{ + instance.web.Sidebar.include( + { + on_attachments_loaded: function(attachments) + { + var result = this._super.apply(this, arguments); + this.$el.find('.oe-sidebar-attachment-edit') + .click(this.on_attachment_edit); + return result; + }, + on_attachment_edit: function(e) + { + var $target = jQuery(e.currentTarget), + attachment_id = parseInt($target.attr('data-id')), + title = $target.attr('title'); + e.preventDefault(); + e.stopPropagation(); + this.do_action({ + type: 'ir_actions.act_window', + name: title, + views: [[false, 'form']], + res_model: 'ir.attachment', + res_id: attachment_id, + flags: { + initial_mode: 'edit', + }, + }); + }, + }) +} diff --git a/attachment_edit/static/src/xml/attachment_edit.xml b/attachment_edit/static/src/xml/attachment_edit.xml new file mode 100644 index 00000000..2a648aa9 --- /dev/null +++ b/attachment_edit/static/src/xml/attachment_edit.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/attachment_edit/views/ir_attachment.xml b/attachment_edit/views/ir_attachment.xml new file mode 100644 index 00000000..ec6eb9da --- /dev/null +++ b/attachment_edit/views/ir_attachment.xml @@ -0,0 +1,14 @@ + + + + + ir.attachment + + + + + + + + + diff --git a/attachment_edit/views/templates.xml b/attachment_edit/views/templates.xml new file mode 100644 index 00000000..e4da3b4b --- /dev/null +++ b/attachment_edit/views/templates.xml @@ -0,0 +1,11 @@ + + + + + +