diff --git a/document_url/README.rst b/document_url/README.rst index 0766dd80..8f4f7b75 100644 --- a/document_url/README.rst +++ b/document_url/README.rst @@ -1,17 +1,36 @@ -.. 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 - ============== URL attachment ============== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/11.0/document_url + :alt: OCA/knowledge +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/knowledge-11-0/knowledge-11-0-document_url + :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/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + Module that allows to attach an URL as a document. -Installation -============ +**Table of contents** -To install this module, you need to click on install +.. contents:: + :local: Usage ===== @@ -21,36 +40,46 @@ To use this module, you need to: * go to menu more and click on add an url. * Insert name and url into the wizard. -.. 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 - 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 -`here `_. +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 +~~~~~~~ + +* Tecnativa + Contributors ------------- +~~~~~~~~~~~~ * Jonathan Nemry -* Pedro M. Baeza `_: -Maintainer ----------- + * Pedro M. Baeza + * Ernesto Tejeda + +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. -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. -To contribute to this module, please visit https://odoo-community.org. +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/document_url/__init__.py b/document_url/__init__.py index 694bfe60..54fd3e95 100644 --- a/document_url/__init__.py +++ b/document_url/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Pedro M. Baeza # © 2016 ACSONE SA/NV () diff --git a/document_url/__openerp__.py b/document_url/__manifest__.py similarity index 89% rename from document_url/__openerp__.py rename to document_url/__manifest__.py index 49659775..e393ffa6 100644 --- a/document_url/__openerp__.py +++ b/document_url/__manifest__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Pedro M. Baeza # © 2016 ACSONE SA/NV () { 'name': 'URL attachment', - 'version': '9.0.1.0.0', + 'version': '11.0.1.0.0', 'category': 'Tools', 'author': "Tecnativa," "Odoo Community Association (OCA)", @@ -15,6 +14,7 @@ ], 'data': [ 'view/document_url_view.xml', + 'security/ir.model.access.csv', ], 'qweb': [ 'static/src/xml/url.xml', diff --git a/document_url/readme/CONTRIBUTORS.rst b/document_url/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..f309e3c0 --- /dev/null +++ b/document_url/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Jonathan Nemry +* `Tecnativa `_: + + * Pedro M. Baeza + * Ernesto Tejeda diff --git a/document_url/readme/DESCRIPTION.rst b/document_url/readme/DESCRIPTION.rst new file mode 100644 index 00000000..e5fe7b45 --- /dev/null +++ b/document_url/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Module that allows to attach an URL as a document. diff --git a/document_url/readme/USAGE.rst b/document_url/readme/USAGE.rst new file mode 100644 index 00000000..85be6a0e --- /dev/null +++ b/document_url/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, you need to: + + * go to menu more and click on add an url. + * Insert name and url into the wizard. diff --git a/document_url/security/ir.model.access.csv b/document_url/security/ir.model.access.csv new file mode 100644 index 00000000..8c8e2e25 --- /dev/null +++ b/document_url/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_ir_attachment_add_url,access_ir_attachment_add_url,model_ir_attachment_add_url,,1,1,1,1 \ No newline at end of file diff --git a/document_url/static/src/js/url.js b/document_url/static/src/js/url.js index 0eaefa47..bf696c92 100644 --- a/document_url/static/src/js/url.js +++ b/document_url/static/src/js/url.js @@ -3,39 +3,59 @@ * © 2016 ACSONE SA/NV () * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */ -odoo.define('document_url', function(require) { +odoo.define('document_url', function (require) { var core = require('web.core'); var Sidebar = require('web.Sidebar'); var ActionManager = require('web.ActionManager'); + var Context = require('web.Context'); + var pyeval = require('web.pyeval'); var _t = core._t, QWeb = core.qweb; Sidebar.include({ - redraw: function() { + _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.$el + .find('.oe_sidebar_add_attachment, .o_sidebar_add_attachment') + .after(QWeb.render('AddUrlDocumentItem', {widget: self})) + self.$el.find('.o_sidebar_add_url').on('click', function (e) { self.on_url_doc(); }); }, - on_url_doc: function() { + on_url_doc: function (event) { + var self = this; + var env = self.env 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, - }, - }); + var ids = self.env.activeIds; + if (!_.isEmpty(ids)) { + var activeIdsContext = { + active_id: env.activeIds[0], + active_ids: env.activeIds, + active_model: env.model, + }; + if (env.domain) { + activeIdsContext.active_domain = env.domain; + } + var context = new Context(env.context, activeIdsContext) + context = pyeval.eval('context', context); + self._rpc({ + route: "/web/action/load", + params: { + action_id: "document_url.action_ir_attachment_add_url", + context: context, + }, + }).done(function (result) { + self.getParent().do_action(result, { + additional_context: { + 'active_ids': ids, + 'active_id': [ids[0]], + 'active_model': env.model, + }, }); }); } diff --git a/document_url/static/src/less/url.less b/document_url/static/src/less/url.less new file mode 100644 index 00000000..2e668f63 --- /dev/null +++ b/document_url/static/src/less/url.less @@ -0,0 +1,9 @@ +.o_cp_sidebar { + .o_sidebar_add_url span { + padding: 3px 25px; + color: @btn-default-color; + } + .o_sidebar_add_url:hover { + background-color: @table-bg-hover; + } +} diff --git a/document_url/static/src/xml/url.xml b/document_url/static/src/xml/url.xml index f55fbc38..75834e9f 100644 --- a/document_url/static/src/xml/url.xml +++ b/document_url/static/src/xml/url.xml @@ -1,8 +1,8 @@ - -
  • - Add URL... -
  • -
    + +
  • + Add URL... +
  • +
    diff --git a/document_url/tests/__init__.py b/document_url/tests/__init__.py new file mode 100644 index 00000000..eecce6c0 --- /dev/null +++ b/document_url/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_document_url diff --git a/document_url/tests/test_document_url.py b/document_url/tests/test_document_url.py new file mode 100644 index 00000000..be262c3c --- /dev/null +++ b/document_url/tests/test_document_url.py @@ -0,0 +1,30 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import common + + +class TestDocumentUrl(common.TransactionCase): + def setUp(self): + super(TestDocumentUrl, self).setUp() + wizard_add_url = self.env['ir.attachment.add_url'] + ctx = { + 'active_model': 'res.users', + 'active_id': self.env.ref('base.user_demo').id, + 'active_ids': [self.env.ref('base.user_demo').id] + } + self.wizard_add_url = wizard_add_url.with_context(ctx).create({ + 'name': 'Demo User (Website)', + 'url': 'http://www.odoodemouser.com' + }) + + def test_add_url_attachment(self): + self.wizard_add_url.action_add_url() + domain = [ + ('type', '=', 'url'), + ('name', '=', 'Demo User (Website)'), + ('url', '=', 'http://www.odoodemouser.com'), + ('res_model', '=', 'res.users'), + ('res_id', '=', self.env.ref('base.user_demo').id) + ] + attachment_added_count = self.env['ir.attachment'].search_count(domain) + self.assertEqual(attachment_added_count, 1) diff --git a/document_url/view/document_url_view.xml b/document_url/view/document_url_view.xml index e8bd2c10..7f1037b0 100644 --- a/document_url/view/document_url_view.xml +++ b/document_url/view/document_url_view.xml @@ -1,39 +1,38 @@ - - + - + - - Add URL - ir.attachment.add_url - ir.actions.act_window - new - form - form - + + Add URL + ir.attachment.add_url + ir.actions.act_window + new + form + form + - - ir.attachment.add_url.form - ir.attachment.add_url - -
    - - - - -
    -
    -
    -
    -
    + + ir.attachment.add_url.form + ir.attachment.add_url + +
    + + + + +
    +
    +
    +
    +
    -
    -
    + diff --git a/document_url/wizard/__init__.py b/document_url/wizard/__init__.py index fb2ce90d..46f7c4a9 100644 --- a/document_url/wizard/__init__.py +++ b/document_url/wizard/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Pedro M. Baeza # © 2016 ACSONE SA/NV () diff --git a/document_url/wizard/document_url.py b/document_url/wizard/document_url.py index 8b7b21eb..7ba56fe5 100644 --- a/document_url/wizard/document_url.py +++ b/document_url/wizard/document_url.py @@ -1,42 +1,32 @@ -# -*- coding: utf-8 -*- # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Pedro M. Baeza # © 2016 ACSONE SA/NV () -from openerp.osv import fields, orm -try: - # Python 3 - from urllib import parse as urlparse -except: - from urlparse import urlparse +from odoo import fields, models +from urllib import parse -class AddUrlWizard(orm.TransientModel): +class AddUrlWizard(models.Model): _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): + 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.env.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) + attachment_obj = self.env['ir.attachment'] + for form in self: + url = parse.urlparse(form.url) if not url.scheme: - url = urlparse('%s%s' % ('http://', form.url)) - for active_id in context.get('active_ids', []): + url = parse.urlparse('%s%s' % ('http://', form.url)) + for active_id in self.env.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'], + 'res_model': self.env.context['active_model'], } - attachment_obj.create(cr, uid, attachment, context=context) + attachment_obj.create(attachment) return {'type': 'ir.actions.act_close_wizard_and_reload_view'}