From d29c02ab7d86abdd645b103fc6971ff6f2104e8f Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 16 Jul 2018 15:21:49 +0200 Subject: [PATCH] [MIG] attachment_edit to 10.0 --- attachment_edit/README.rst | 69 ++- .../{__openerp__.py => __manifest__.py} | 12 +- attachment_edit/models/ir_attachment.py | 26 +- attachment_edit/readme/CONTRIBUTORS.rst | 1 + attachment_edit/readme/DESCRIPTION.rst | 6 + attachment_edit/readme/USAGE.rst | 5 + attachment_edit/static/description/index.html | 409 ++++++++++++++++++ .../static/src/css/attachment_edit.css | 22 - .../static/src/js/attachment_edit.js | 51 +-- .../static/src/xml/attachment_edit.xml | 6 +- attachment_edit/tests/__init__.py | 4 + attachment_edit/tests/test_attachment_edit.py | 26 ++ attachment_edit/views/ir_attachment.xml | 22 +- attachment_edit/views/templates.xml | 1 - 14 files changed, 541 insertions(+), 119 deletions(-) rename attachment_edit/{__openerp__.py => __manifest__.py} (68%) create mode 100644 attachment_edit/readme/CONTRIBUTORS.rst create mode 100644 attachment_edit/readme/DESCRIPTION.rst create mode 100644 attachment_edit/readme/USAGE.rst create mode 100644 attachment_edit/static/description/index.html delete mode 100644 attachment_edit/static/src/css/attachment_edit.css create mode 100644 attachment_edit/tests/__init__.py create mode 100644 attachment_edit/tests/test_attachment_edit.py diff --git a/attachment_edit/README.rst b/attachment_edit/README.rst index d5f657e3..3176af0e 100644 --- a/attachment_edit/README.rst +++ b/attachment_edit/README.rst @@ -1,11 +1,30 @@ -.. 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 file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github + :target: https://github.com/OCA/knowledge/tree/10.0/attachment_edit + :alt: OCA/knowledge +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/knowledge-10-0/knowledge-10-0-attachment_edit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/118/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + 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. @@ -13,6 +32,11 @@ attachment's properties after upload. On the attachment's form, a field is added to move the attachment to another record. +**Table of contents** + +.. contents:: + :local: + Usage ===== @@ -22,41 +46,42 @@ 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 -`_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Therp BV + Contributors ------------- +~~~~~~~~~~~~ * Holger Brunn -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/knowledge `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/attachment_edit/__openerp__.py b/attachment_edit/__manifest__.py similarity index 68% rename from attachment_edit/__openerp__.py rename to attachment_edit/__manifest__.py index cd5e14ae..c0a1f135 100644 --- a/attachment_edit/__openerp__.py +++ b/attachment_edit/__manifest__.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- -# © 2015 Therp BV +# © 2015-2018 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Edit attachments", - "version": "8.0.1.0.0", + "version": "10.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Knowledge Management", "summary": "Edit attachments after upload", "depends": [ - 'web', + 'attachment_action', ], "data": [ "views/ir_attachment.xml", @@ -18,10 +18,4 @@ "qweb": [ 'static/src/xml/attachment_edit.xml', ], - "auto_install": False, - "installable": True, - "application": False, - "external_dependencies": { - 'python': [], - }, } diff --git a/attachment_edit/models/ir_attachment.py b/attachment_edit/models/ir_attachment.py index 04da13b0..d50cea20 100644 --- a/attachment_edit/models/ir_attachment.py +++ b/attachment_edit/models/ir_attachment.py @@ -13,25 +13,27 @@ class IrAttachment(models.Model): string='Resource reference', compute='_compute_res_reference', inverse='_inverse_res_reference') - @api.one + @api.multi @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) + for this in self: + if this.res_model and this.res_id: + this.res_reference = '%s,%s' % (this.res_model, this.res_id) - @api.one + @api.multi 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}) + for this in self: + if this.res_reference: + this.write({ + 'res_model': this.res_reference._name, + 'res_id': this.res_reference.id, + }) + else: + this.write({'res_model': False, 'res_id': False}) @api.model def _selection_res_reference(self): return self.env['ir.model'].search([ - ('osv_memory', '=', False), + ('transient', '=', False), ('access_ids.group_id.users', '=', self.env.uid) ]).mapped(lambda rec: (rec.model, rec.name)) diff --git a/attachment_edit/readme/CONTRIBUTORS.rst b/attachment_edit/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b120a956 --- /dev/null +++ b/attachment_edit/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Holger Brunn diff --git a/attachment_edit/readme/DESCRIPTION.rst b/attachment_edit/readme/DESCRIPTION.rst new file mode 100644 index 00000000..45ed5907 --- /dev/null +++ b/attachment_edit/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +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. diff --git a/attachment_edit/readme/USAGE.rst b/attachment_edit/readme/USAGE.rst new file mode 100644 index 00000000..0934f2e1 --- /dev/null +++ b/attachment_edit/readme/USAGE.rst @@ -0,0 +1,5 @@ +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`. diff --git a/attachment_edit/static/description/index.html b/attachment_edit/static/description/index.html new file mode 100644 index 00000000..8ce25d3b --- /dev/null +++ b/attachment_edit/static/description/index.html @@ -0,0 +1,409 @@ + + + + + + +Edit attachments + + + +
+

Edit attachments

+ + +

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runbot

+

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.

+

Table of contents

+ +
+

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.

+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/knowledge project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/attachment_edit/static/src/css/attachment_edit.css b/attachment_edit/static/src/css/attachment_edit.css deleted file mode 100644 index 3b25edd3..00000000 --- a/attachment_edit/static/src/css/attachment_edit.css +++ /dev/null @@ -1,22 +0,0 @@ -.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 index 65234fd2..10002aac 100644 --- a/attachment_edit/static/src/js/attachment_edit.js +++ b/attachment_edit/static/src/js/attachment_edit.js @@ -1,45 +1,22 @@ //-*- 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 . -// -//############################################################################ +// (c) 2015-2018 Therp BV +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +odoo.define('attachment_edit', function(require) { + var Sidebar = require('web.Sidebar'); -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; + Sidebar.include({ + on_attachments_loaded: function() { + this._super.apply(this, arguments); + this.$('.o_sidebar_edit_attachment') + .click(this.proxy('on_attachment_edit')); }, - on_attachment_edit: function(e) - { + on_attachment_edit: function(e) { var $target = jQuery(e.currentTarget), - attachment_id = parseInt($target.attr('data-id')), - title = $target.attr('title'); + attachment_id = parseInt($target.attr('data-id'), 10); e.preventDefault(); e.stopPropagation(); - this.do_action({ + return this.do_action({ type: 'ir_actions.act_window', - name: title, views: [[false, 'form']], res_model: 'ir.attachment', res_id: attachment_id, @@ -48,5 +25,5 @@ openerp.attachment_edit = function(instance) }, }); }, - }) -} + }); +}); diff --git a/attachment_edit/static/src/xml/attachment_edit.xml b/attachment_edit/static/src/xml/attachment_edit.xml index 2a648aa9..c664ca09 100644 --- a/attachment_edit/static/src/xml/attachment_edit.xml +++ b/attachment_edit/static/src/xml/attachment_edit.xml @@ -1,10 +1,8 @@ - - - - + + diff --git a/attachment_edit/tests/__init__.py b/attachment_edit/tests/__init__.py new file mode 100644 index 00000000..7d99b068 --- /dev/null +++ b/attachment_edit/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_attachment_edit diff --git a/attachment_edit/tests/test_attachment_edit.py b/attachment_edit/tests/test_attachment_edit.py new file mode 100644 index 00000000..60a9b95a --- /dev/null +++ b/attachment_edit/tests/test_attachment_edit.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import SUPERUSER_ID +from odoo.tests.common import TransactionCase + + +class TestAttachmentEdit(TransactionCase): + def test_attachment_edit(self): + attachment = self.env['ir.attachment'].create({ + 'name': 'attachment', + }) + self.assertFalse(attachment.res_reference) + attachment.write({ + 'res_model': 'res.users', + 'res_id': SUPERUSER_ID, + }) + self.assertEqual( + attachment.res_reference, self.env.ref('base.user_root'), + ) + attachment.res_reference = None + self.assertFalse(attachment.res_model) + self.assertFalse(attachment.res_id) + attachment.res_reference = self.env.ref('base.user_root') + self.assertEqual(attachment.res_model, 'res.users') + self.assertEqual(attachment.res_id, SUPERUSER_ID) diff --git a/attachment_edit/views/ir_attachment.xml b/attachment_edit/views/ir_attachment.xml index ec6eb9da..f7fbf214 100644 --- a/attachment_edit/views/ir_attachment.xml +++ b/attachment_edit/views/ir_attachment.xml @@ -1,14 +1,12 @@ - - - - ir.attachment - - - - - + + + ir.attachment + + + + - - - + + + diff --git a/attachment_edit/views/templates.xml b/attachment_edit/views/templates.xml index e4da3b4b..f51deabe 100644 --- a/attachment_edit/views/templates.xml +++ b/attachment_edit/views/templates.xml @@ -4,7 +4,6 @@