From 8cf1e5aa804e79bef3412208d397564d4dfda306 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 10 Sep 2014 17:54:42 +0200 Subject: [PATCH 1/3] [ADD] document_url: A module that allows to put URLs as attached documents. --- document_url/__init__.py | 22 +++++++++ document_url/__openerp__.py | 45 ++++++++++++++++++ document_url/i18n/document_url.pot | 62 +++++++++++++++++++++++++ document_url/i18n/es.po | 62 +++++++++++++++++++++++++ document_url/model/__init__.py | 22 +++++++++ document_url/model/document_url.py | 59 +++++++++++++++++++++++ document_url/static/src/js/url.js | 46 ++++++++++++++++++ document_url/static/src/xml/url.xml | 8 ++++ document_url/view/document_url_view.xml | 33 +++++++++++++ 9 files changed, 359 insertions(+) create mode 100644 document_url/__init__.py create mode 100644 document_url/__openerp__.py create mode 100644 document_url/i18n/document_url.pot create mode 100644 document_url/i18n/es.po create mode 100644 document_url/model/__init__.py create mode 100644 document_url/model/document_url.py create mode 100644 document_url/static/src/js/url.js create mode 100644 document_url/static/src/xml/url.xml create mode 100644 document_url/view/document_url_view.xml diff --git a/document_url/__init__.py b/document_url/__init__.py new file mode 100644 index 00000000..940101d2 --- /dev/null +++ b/document_url/__init__.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) +# Pedro M. Baeza +# +# 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 . +# +############################################################################## +from . import model diff --git a/document_url/__openerp__.py b/document_url/__openerp__.py new file mode 100644 index 00000000..0880a996 --- /dev/null +++ b/document_url/__openerp__.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) +# Pedro M. Baeza +# +# 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 . +# +############################################################################## + +{ + 'name': 'URL attachment', + 'version': '1.0', + 'category': 'Tools', + 'description': """ +Module that allows to attach an URL as a document. + """, + 'author': 'Serv. Tecnolog. Avanzados - Pedro M. Baeza', + 'website' : 'http://www.serviciosbaeza.com', + 'depends': [ + 'document', + ], + 'js': [ + 'static/src/js/url.js', + ], + 'qweb': [ + 'static/src/xml/url.xml', + ], + 'data': [ + 'view/document_url_view.xml', + ], + "installable": True, +} diff --git a/document_url/i18n/document_url.pot b/document_url/i18n/document_url.pot new file mode 100644 index 00000000..806ad4f2 --- /dev/null +++ b/document_url/i18n/document_url.pot @@ -0,0 +1,62 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * document_url +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-05 01:48+0000\n" +"PO-Revision-Date: 2014-04-05 03:49+0100\n" +"Last-Translator: Pedro Manuel Baeza \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" + +#. module: document_url +#: view:ir.attachment.add_url:0 +msgid "Add" +msgstr "" + +#. module: document_url +#: model:ir.actions.act_window,name:document_url.action_ir_attachment_add_url +#: view:ir.attachment.add_url:0 +msgid "Add URL" +msgstr "" + +#. module: document_url +#. openerp-web +#: code:addons/document_url/static/src/xml/url.xml:6 +#, python-format +msgid "Add URL..." +msgstr "" + +#. module: document_url +#: view:ir.attachment.add_url:0 +msgid "Cancel" +msgstr "" + +#. module: document_url +#: field:ir.attachment.add_url,name:0 +msgid "Name" +msgstr "" + +#. module: document_url +#: field:ir.attachment.add_url,url:0 +msgid "URL" +msgstr "" + +#. module: document_url +#: code:_description:0 +#: model:ir.model,name:document_url.model_ir_attachment_add_url +#, python-format +msgid "ir.attachment.add_url" +msgstr "" + +#. module: document_url +#: view:ir.attachment.add_url:0 +msgid "or" +msgstr "" + diff --git a/document_url/i18n/es.po b/document_url/i18n/es.po new file mode 100644 index 00000000..25ec9070 --- /dev/null +++ b/document_url/i18n/es.po @@ -0,0 +1,62 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * document_url +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-05 01:48+0000\n" +"PO-Revision-Date: 2014-04-05 03:50+0100\n" +"Last-Translator: Pedro Manuel Baeza \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" + +#. module: document_url +#: view:ir.attachment.add_url:0 +msgid "Add" +msgstr "Añadir" + +#. module: document_url +#: model:ir.actions.act_window,name:document_url.action_ir_attachment_add_url +#: view:ir.attachment.add_url:0 +msgid "Add URL" +msgstr "Añadir URL" + +#. module: document_url +#. openerp-web +#: code:addons/document_url/static/src/xml/url.xml:6 +#, python-format +msgid "Add URL..." +msgstr "Añadir URL..." + +#. module: document_url +#: view:ir.attachment.add_url:0 +msgid "Cancel" +msgstr "Cancelar" + +#. module: document_url +#: field:ir.attachment.add_url,name:0 +msgid "Name" +msgstr "Nombre" + +#. module: document_url +#: field:ir.attachment.add_url,url:0 +msgid "URL" +msgstr "URL" + +#. module: document_url +#: code:_description:0 +#: model:ir.model,name:document_url.model_ir_attachment_add_url +#, python-format +msgid "ir.attachment.add_url" +msgstr "ir.attachment.add_url" + +#. module: document_url +#: view:ir.attachment.add_url:0 +msgid "or" +msgstr "o" + diff --git a/document_url/model/__init__.py b/document_url/model/__init__.py new file mode 100644 index 00000000..e036314c --- /dev/null +++ b/document_url/model/__init__.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) +# Pedro M. Baeza +# +# 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 . +# +############################################################################## +from . import document_url diff --git a/document_url/model/document_url.py b/document_url/model/document_url.py new file mode 100644 index 00000000..01e50b87 --- /dev/null +++ b/document_url/model/document_url.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## +from openerp.osv import fields, orm +try: + # Python 3 + from urllib import parse as urlparse +except: + from urlparse import urlparse + +class AddUrlWizard(orm.TransientModel): + _name = 'ir.attachment.add_url' + + _columns = { + 'name': fields.char('Name', required=True), + 'url': fields.char('URL', required=True), + } + + def action_add_url(self, cr, uid, ids, context=None): + """ + Adds the URL with the given name as an ir.attachment record. + """ + if context is None: + context = {} + if not context.get('active_model'): + return + attachment_obj = self.pool['ir.attachment'] + for form in self.browse(cr, uid, ids, context=context): + url = urlparse(form.url) + if not url.scheme: + url = urlparse('%s%s' % ('http://', form.url)) + for active_id in context.get('active_ids', []): + attachment = { + 'name': form.name, + 'type': 'url', + 'url': url.geturl(), + 'user_id': uid, + 'res_id': active_id, + 'res_model': context['active_model'], + } + attachment_obj.create(cr, uid, attachment, context=context) + return { 'type' : 'ir.actions.act_close_wizard_and_reload_view' } diff --git a/document_url/static/src/js/url.js b/document_url/static/src/js/url.js new file mode 100644 index 00000000..efc2e80d --- /dev/null +++ b/document_url/static/src/js/url.js @@ -0,0 +1,46 @@ +openerp.document_url = function(instance, m) { + + instance.web.ActionManager = instance.web.ActionManager.extend({ + + ir_actions_act_close_wizard_and_reload_view: function (action, options) { + if (!this.dialog) { + options.on_close(); + } + this.dialog_stop(); + this.inner_widget.views[this.inner_widget.active_view].controller.reload(); + return $.when(); + }, + }); + + var _t = instance.web._t, + QWeb = instance.web.qweb; + instance.web.Sidebar.include({ + redraw: function() { + var self = this; + this._super.apply(this, arguments); + self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddUrlDocumentItem', {widget: self})) + self.$el.find('.oe_sidebar_add_url').on('click', function (e) { + self.on_url_doc(); + }); + }, + on_url_doc: function() { + var self = this; + var view = self.getParent(); + var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; + if( !_.isEmpty(ids) ){ + view.sidebar_eval_context().done(function (context) { + self.rpc("/web/action/load", { action_id: "document_url.action_ir_attachment_add_url" }).done(function(result) { + self.getParent().do_action(result, { + additional_context: { + 'active_ids': ids, + 'active_id': [ids[0]], + 'active_model': view.dataset.model, + }, + }); + }); + }); + } + + } + }); +}; diff --git a/document_url/static/src/xml/url.xml b/document_url/static/src/xml/url.xml new file mode 100644 index 00000000..de8fc9cd --- /dev/null +++ b/document_url/static/src/xml/url.xml @@ -0,0 +1,8 @@ + + + + +
  • Add URL...
  • +
    +
    diff --git a/document_url/view/document_url_view.xml b/document_url/view/document_url_view.xml new file mode 100644 index 00000000..2bc75818 --- /dev/null +++ b/document_url/view/document_url_view.xml @@ -0,0 +1,33 @@ + + + + + + Add URL + ir.attachment.add_url + ir.actions.act_window + new + form + form + + + + ir.attachment.add_url.form + ir.attachment.add_url + +
    + + + + +
    +
    +
    +
    +
    + +
    +
    From a522eccebc93c073f62eb4427f3580288bcaf7c3 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 11 Sep 2014 16:06:21 +0200 Subject: [PATCH 2/3] Some fixes --- document_url/model/document_url.py | 11 +++++------ document_url/static/src/js/url.js | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/document_url/model/document_url.py b/document_url/model/document_url.py index 01e50b87..c33cc21e 100644 --- a/document_url/model/document_url.py +++ b/document_url/model/document_url.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). +# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) +# Pedro M. Baeza # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -25,6 +25,7 @@ try: except: from urlparse import urlparse + class AddUrlWizard(orm.TransientModel): _name = 'ir.attachment.add_url' @@ -34,9 +35,7 @@ class AddUrlWizard(orm.TransientModel): } def action_add_url(self, cr, uid, ids, context=None): - """ - Adds the URL with the given name as an ir.attachment record. - """ + """Adds the URL with the given name as an ir.attachment record.""" if context is None: context = {} if not context.get('active_model'): @@ -56,4 +55,4 @@ class AddUrlWizard(orm.TransientModel): 'res_model': context['active_model'], } attachment_obj.create(cr, uid, attachment, context=context) - return { 'type' : 'ir.actions.act_close_wizard_and_reload_view' } + return {'type': 'ir.actions.act_close_wizard_and_reload_view'} diff --git a/document_url/static/src/js/url.js b/document_url/static/src/js/url.js index efc2e80d..1b22b42c 100644 --- a/document_url/static/src/js/url.js +++ b/document_url/static/src/js/url.js @@ -13,7 +13,7 @@ openerp.document_url = function(instance, m) { }); var _t = instance.web._t, - QWeb = instance.web.qweb; + QWeb = instance.web.qweb; instance.web.Sidebar.include({ redraw: function() { var self = this; From 52d7eb8e6d7544f35a833fb1d74f2c7736691218 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 12 Sep 2014 11:16:45 +0200 Subject: [PATCH 3/3] Some PEP8 fixes and Travis update --- .travis.yml | 9 ++++----- document_url/__init__.py | 2 +- document_url/__openerp__.py | 4 ++-- document_url/model/__init__.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83c4a04e..c58be69f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ python: - "2.7" env: - - VERSION="7.0" + - VERSION="7.0" ODOO_REPO="odoo/odoo" + - VERSION="7.0" ODOO_REPO="OCA/OCB" virtualenv: system_site_packages: true @@ -12,12 +13,10 @@ virtualenv: install: - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - - travis_install_nightly ${VERSION} - - $HOME/maintainer-quality-tools/travis/travis_install_nightly ${VERSION} + - travis_install_nightly script: - - travis_run_flake8 - - travis_run_tests ${VERSION} + - travis_run_tests after_success: coveralls diff --git a/document_url/__init__.py b/document_url/__init__.py index 940101d2..3db8503d 100644 --- a/document_url/__init__.py +++ b/document_url/__init__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza +# Pedro M. Baeza # # 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 diff --git a/document_url/__openerp__.py b/document_url/__openerp__.py index 0880a996..dda23d22 100644 --- a/document_url/__openerp__.py +++ b/document_url/__openerp__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza +# Pedro M. Baeza # # 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 @@ -28,7 +28,7 @@ Module that allows to attach an URL as a document. """, 'author': 'Serv. Tecnolog. Avanzados - Pedro M. Baeza', - 'website' : 'http://www.serviciosbaeza.com', + 'website': 'http://www.serviciosbaeza.com', 'depends': [ 'document', ], diff --git a/document_url/model/__init__.py b/document_url/model/__init__.py index e036314c..8853063f 100644 --- a/document_url/model/__init__.py +++ b/document_url/model/__init__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza +# Pedro M. Baeza # # 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