From f14a006edc87b1a4bdfa07dcecee27c2321e3a2f Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 24 Oct 2014 20:08:51 +0200 Subject: [PATCH] [ADD] document_url: Module to attach URLs as documents --- document_url/__init__.py | 22 ++++++ document_url/__openerp__.py | 44 +++++++++++ document_url/i18n/document_url.pot | 62 +++++++++++++++ document_url/i18n/es.po | 62 +++++++++++++++ document_url/static/description/icon.png | Bin 0 -> 1834 bytes document_url/static/description/icon.svg | 91 +++++++++++++++++++++++ document_url/static/src/js/url.js | 45 +++++++++++ document_url/static/src/xml/url.xml | 6 ++ document_url/view/document_url_view.xml | 39 ++++++++++ document_url/wizard/__init__.py | 22 ++++++ document_url/wizard/document_url.py | 58 +++++++++++++++ 11 files changed, 451 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/static/description/icon.png create mode 100644 document_url/static/description/icon.svg 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 create mode 100644 document_url/wizard/__init__.py create mode 100644 document_url/wizard/document_url.py diff --git a/document_url/__init__.py b/document_url/__init__.py new file mode 100644 index 00000000..73bd7c2a --- /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 wizard diff --git a/document_url/__openerp__.py b/document_url/__openerp__.py new file mode 100644 index 00000000..31d8f43c --- /dev/null +++ b/document_url/__openerp__.py @@ -0,0 +1,44 @@ +# -*- 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': '8.0.1.0.0', + 'category': 'Tools', + 'description': """ +Module that allows to attach an URL as a document. + """, + 'author': "Serv. Tecnolog. Avanzados - Pedro M. Baeza," + "Odoo Community Association (OCA)", + 'website': 'http://www.serviciosbaeza.com', + 'license': 'AGPL-3', + 'depends': [ + 'document', + ], + 'data': [ + 'view/document_url_view.xml', + ], + 'qweb': [ + 'static/src/xml/url.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/static/description/icon.png b/document_url/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f571f7f17fc8655b1098ca0062406865b87c4021 GIT binary patch literal 1834 zcmcgt`&-fn7yoiIMNx=}Xn38M?9~vPio**U7L=lITAI{Ak!|TT6_qYtzLfX0$ks&x z&8Leq4P7n@do{{Z(}wmqb%{<&7g>s|(kzYlW&3IWz~1vbpYwUn`JA85bDs05h+%F= zA?=U=0H7Fj+Abr5f5Oznn0rE!28{&ghcn_#jgfDfQf{oxGU;#`JVev3(dH$Fzw{$%4|;76Lp5tUPHvx zrpkr<3|qac^sU=%^Qy}JPc8wklJ_8URo;j^NE>7bGPQF26_ODU@E#Po5j`L;E z@1S`wme6`da_U@7djkA6q6&x?5`}!1H-Z&hMB=8kw%#yJnx+tU&E60C-2qXD)e0V; z&h7PmRXAp|PMA9Q>1ncd@u7HJCv|`x`TEhXuzX~syQpKn6FKj_58$ADE+{RLnf5OS z9^FQ-0QhJp?wvGrLTovp4B>bQr8QoCosz2kN-Ffju4^QYpdDB-SG)(C;d$F`5Ul3W z?KnKsiCyW3AfT)@DNsrbYkRhDhO?C2^!;nvPAE`@HQmpO2Y09*{?=1i!cMWz*a2`T zKBuXgiHW`EvoM)~!hO;>ta7;&3bg1ir7l>qSf2uG>UTKBdyLt0c%MU<9_Sn0{$spJ z3H2&dHllz68|d1~qE6L|{MCg#qUOMPFdv#U^hctldkWcSgsoU7!9KYrXbu zLQAp1wd~C|R54GbaQo3wlFr>r9T7by6~B8#Kil4LQpCD}FBMM1CeoqZ6>Ib9!i9m5 zsM5bgHaMzMEb*qyQsPItc=>xQ+t$g=17%@k?bygigp;xwS%@bWzlW)FEmR7v@D{X= z8Kd)b`iUru2j2>-1%X;iggmN#ezM3e0X>`_L(}01p66Sw@(})^p~3Y*k9iXF2>vEWTU;r}K2RL8$a_F-vy?*a**rbi3%NcVx>7%1cflzil=pqFNC*MIH zvJUlh%?t1M$IP|eyw*Uz)SAE0yeij4JH-|(4b8Tg)jhvF%xn=#8eVsp&0f2{#%SF8 z>t{_Rf?eq{O8o|Ge;oV6$o&rGzZi=TMa<^dz-fa4o;_;3^U+plN@HxkpVv~Sh1Y;W z{H;JXQMWqUUZ-#FBGhG9@4A&}W^h)Yh2I$6!zY%F%|EDshc|u2oo$VU6BtgcbgATK zgBG7juAH)cyr)MwA>qm?ja>f{_G}NrET&_t+_dMvY2aFJ<(OMeYcE*9Up{zd>nTs~ z^`k1gJ|gX=j~1VcF&v9}vU}3y-?^090pBd%xNG5@V%yFUl$(fOc&?&F{WK0&>2+z_ zA19)g{m2e1{h82-v!v9VSvcp|{{V;iE)oC$ literal 0 HcmV?d00001 diff --git a/document_url/static/description/icon.svg b/document_url/static/description/icon.svg new file mode 100644 index 00000000..148a9d18 --- /dev/null +++ b/document_url/static/description/icon.svg @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/document_url/static/src/js/url.js b/document_url/static/src/js/url.js new file mode 100644 index 00000000..1285fd6f --- /dev/null +++ b/document_url/static/src/js/url.js @@ -0,0 +1,45 @@ +openerp.document_url = function(instance, m) { + 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, + }, + }); + }); + }); + } + }, + }); + + 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(); + }, + }); + +}; diff --git a/document_url/static/src/xml/url.xml b/document_url/static/src/xml/url.xml new file mode 100644 index 00000000..6af648f2 --- /dev/null +++ b/document_url/static/src/xml/url.xml @@ -0,0 +1,6 @@ + + + +
  • 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..e8bd2c10 --- /dev/null +++ b/document_url/view/document_url_view.xml @@ -0,0 +1,39 @@ + + + + + + + + Add URL + ir.attachment.add_url + ir.actions.act_window + new + form + form + + + + ir.attachment.add_url.form + ir.attachment.add_url + +
    + + + + +
    +
    +
    +
    +
    + +
    +
    diff --git a/document_url/wizard/__init__.py b/document_url/wizard/__init__.py new file mode 100644 index 00000000..8853063f --- /dev/null +++ b/document_url/wizard/__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/wizard/document_url.py b/document_url/wizard/document_url.py new file mode 100644 index 00000000..c68f80b1 --- /dev/null +++ b/document_url/wizard/document_url.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# 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 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'}