Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions document_url/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ To use this module, you need to:

.. 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/9.0
:target: https://runbot.odoo-community.org/runbot/118/10.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/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
`here <https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`here <https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======
Expand All @@ -40,7 +40,7 @@ Contributors
------------

* Jonathan Nemry <jonathan.nemry@acsone.eu>
* Pedro M. Baeza <pedro.baeza@tecnativa.com
* Pedro M. Baeza <pedro.baeza@tecnativa.com>

Maintainer
----------
Expand Down
4 changes: 2 additions & 2 deletions document_url/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
{
'name': 'URL attachment',
'version': '9.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'Tools',
'author': "Tecnativa,"
"Odoo Community Association (OCA)",
Expand All @@ -19,5 +19,5 @@
'qweb': [
'static/src/xml/url.xml',
],
'installable': False,
'installable': True,
}
58 changes: 16 additions & 42 deletions document_url/static/src/js/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,27 @@
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('document_url', function(require) {

var core = require('web.core');
"use strict";
var Sidebar = require('web.Sidebar');
var ActionManager = require('web.ActionManager');

var _t = core._t,
QWeb = core.qweb;

Sidebar.include({
redraw: function() {
var self = this;
this._super.apply(this, arguments);
self.$el.find("a[href]").attr('target', '_blank');
self.$el.find('.oe_sidebar_add_attachment, .o_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,
},
});
});
});
}
init: function (parent, options) {
var result = this._super(parent, options);
this.items.url_doc = [
{
action: {
id: "document_url.action_ir_attachment_add_url",
},
},
];
return result;
},
});

ActionManager = ActionManager.include({
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.type].controller.reload();
return $.when();
redraw: function () {
var result = this._super();
// Open URLs in a different browser tab
this.$el.find("a[href]").attr('target', '_blank');
return result;
},
});

});
19 changes: 13 additions & 6 deletions document_url/static/src/xml/url.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="AddUrlDocumentItem">
<li class="oe_sidebar_add_url">
<a class="oe_file_attachment">Add URL...</a>
</li>
</t>
<templates>
<t t-extend="Sidebar">
<!-- oe_ for Odoo CE, and o_ for Odoo EE -->
<t t-jquery=".oe_sidebar_add_attachment, .o_sidebar_add_attachment"
t-operation="after">
<li class="oe_sidebar_add_url"
t-if="section.name == 'files' and widget.options.editable">
<a class="oe_file_attachment"
data-section="url_doc"
data-index="0">Add URL...</a>
</li>
</t>
</t>
</templates>
8 changes: 2 additions & 6 deletions document_url/view/document_url_view.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<odoo>
<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>
Expand Down Expand Up @@ -34,6 +32,4 @@
</form>
</field>
</record>

</data>
</openerp>
</odoo>
31 changes: 14 additions & 17 deletions document_url/wizard/document_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,38 @@
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
from openerp.osv import fields, orm
from odoo import models, fields, api, _
try:
# Python 3
from urllib import parse as urlparse
except:
from urlparse import urlparse


class AddUrlWizard(orm.TransientModel):
class AddUrlWizard(models.TransientModel):
_name = 'ir.attachment.add_url'

_columns = {
'name': fields.char('Name', required=True),
'url': fields.char('URL', required=True),
}
name = fields.Char('Name', required=True)
url = fields.Char('URL', required=True)

def action_add_url(self, cr, uid, ids, context=None):
@api.multi
def action_add_url(self):
"""Adds the URL with the given name as an ir.attachment record."""
if context is None:
context = {}
if not context.get('active_model'):

if not self._context.get('active_model'):
return
attachment_obj = self.pool['ir.attachment']
for form in self.browse(cr, uid, ids, context=context):
attachment_obj = self.env['ir.attachment']
for form in self:
url = urlparse(form.url)
if not url.scheme:
url = urlparse('%s%s' % ('http://', form.url))
for active_id in context.get('active_ids', []):
for active_id in self._context.get('active_ids', []):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self.env.context instead.

attachment = {
'name': form.name,
'type': 'url',
'url': url.geturl(),
'user_id': uid,
'res_id': active_id,
'res_model': context['active_model'],
'res_model': self._context.get('active_model')
}
attachment_obj.create(cr, uid, attachment, context=context)
return {'type': 'ir.actions.act_close_wizard_and_reload_view'}
attachment_obj.create(attachment)
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the return value now empty?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this action repoen the wizard is it a "quick next encode"? I agree with @difusionvisual to replace this by return false...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was because in older versions of Odoo, it didn't refresh the view and you didn't see the new attachment number. I don't know if this happens also in v10.