[ADD] document_url: Module to attach URLs as documents

This commit is contained in:
Pedro M. Baeza 2014-10-24 20:08:51 +02:00 committed by Bhavesh Heliconia
parent a014c5a848
commit f14a006edc
11 changed files with 451 additions and 0 deletions

22
document_url/__init__.py Normal file
View File

@ -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 <pedro.baeza@serviciosbaeza.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import wizard

View File

@ -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 <pedro.baeza@serviciosbaeza.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}

View File

@ -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 <pedro.baeza@serviciosbaeza.com>\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 ""

62
document_url/i18n/es.po Normal file
View File

@ -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 <pedro.baeza@serviciosbaeza.com>\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"

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="128"
height="128"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="icon.svg"
inkscape:export-filename="icon.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4">
<clipPath
id="clipPath3843">
<path
d="m-127.28-391.22v-60.411h-52.004l-46.808 13.214h-5v-8.9286c0-22.333 18.422-40.719 40.75-40.719h63.062v-11.25h-176.28v108.09z"
style="color:#000000;fill:#999999"
id="path3845" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.959798"
inkscape:cx="89.019333"
inkscape:cy="32.209224"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1861"
inkscape:window-height="1176"
inkscape:window-x="59"
inkscape:window-y="24"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Capa 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-924.36218)">
<g
transform="matrix(0.66692461,0,0,0.66692461,-45.072185,690.02679)"
id="layer1-8">
<rect
x="-277.23001"
y="-470.57001"
width="109.54"
height="46.466999"
ry="23.233999"
rx="23.233999"
clip-path="url(#clipPath3843)"
transform="matrix(-1,0,0,-1,-27.857,0)"
style="color:#000000;fill:none;stroke:#000000;stroke-width:20"
id="rect3796" />
<use
x="0"
y="0"
width="744.09448"
height="1052.3622"
transform="matrix(-1,0,0,-1,327.09,894.66)"
xlink:href="#rect3796"
id="use3832" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -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();
},
});
};

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="AddUrlDocumentItem">
<li class="oe_sidebar_add_url"><span><b>Add URL...</b></span></li>
</t>
</templates>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="google_drive assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/document_url/static/src/js/url.js"></script>
</xpath>
</template>
<record model='ir.actions.act_window' id='action_ir_attachment_add_url'>
<field name='name'>Add URL</field>
<field name='res_model'>ir.attachment.add_url</field>
<field name='type'>ir.actions.act_window</field>
<field name='target'>new</field>
<field name='view_type'>form</field>
<field name='view_mode'>form</field>
</record>
<record model="ir.ui.view" id="view_ir_attachment_add_url_form">
<field name="name">ir.attachment.add_url.form</field>
<field name="model">ir.attachment.add_url</field>
<field name="arch" type="xml">
<form string="Add URL" version="7.0">
<group>
<field name="name"/>
<field name="url" widget="url"/>
</group>
<footer>
<button name="action_add_url" string="Add" class="oe_highlight" type="object" />
or
<button special="cancel" string="Cancel" class="oe_link" />
</footer>
</form>
</field>
</record>
</data>
</openerp>

View File

@ -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 <pedro.baeza@serviciosbaeza.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import document_url

View File

@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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'}