[MIG] document_url: Migration to 11.0

This commit is contained in:
ernesto 2018-04-28 09:02:51 -04:00 committed by Bhavesh Heliconia
parent d9b6f859e3
commit 97f4a91d94
15 changed files with 193 additions and 103 deletions

View File

@ -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 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. 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 Usage
===== =====
@ -21,36 +40,46 @@ To use this module, you need to:
* go to menu more and click on add an url. * go to menu more and click on add an url.
* Insert name and url into the wizard. * 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 Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_. 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. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
`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**>`_. `feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits Credits
======= =======
Authors
~~~~~~~
* Tecnativa
Contributors Contributors
------------ ~~~~~~~~~~~~
* Jonathan Nemry <jonathan.nemry@acsone.eu> * Jonathan Nemry <jonathan.nemry@acsone.eu>
* Pedro M. Baeza <pedro.baeza@tecnativa.com * `Tecnativa <https://www.tecnativa.com>`_:
Maintainer * Pedro M. Baeza
---------- * Ernesto Tejeda
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png .. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association :alt: Odoo Community Association
:target: https://odoo-community.org :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 <https://github.com/OCA/knowledge/tree/11.0/document_url>`_ 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.

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>) # © 2016 ACSONE SA/NV (<http://acsone.eu>)

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>) # © 2016 ACSONE SA/NV (<http://acsone.eu>)
{ {
'name': 'URL attachment', 'name': 'URL attachment',
'version': '9.0.1.0.0', 'version': '11.0.1.0.0',
'category': 'Tools', 'category': 'Tools',
'author': "Tecnativa," 'author': "Tecnativa,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
@ -15,6 +14,7 @@
], ],
'data': [ 'data': [
'view/document_url_view.xml', 'view/document_url_view.xml',
'security/ir.model.access.csv',
], ],
'qweb': [ 'qweb': [
'static/src/xml/url.xml', 'static/src/xml/url.xml',

View File

@ -0,0 +1,5 @@
* Jonathan Nemry <jonathan.nemry@acsone.eu>
* `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza
* Ernesto Tejeda

View File

@ -0,0 +1 @@
Module that allows to attach an URL as a document.

View File

@ -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.

View File

@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_ir_attachment_add_url access_ir_attachment_add_url model_ir_attachment_add_url 1 1 1 1

View File

@ -3,39 +3,59 @@
* © 2016 ACSONE SA/NV (<http://acsone.eu>) * © 2016 ACSONE SA/NV (<http://acsone.eu>)
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). * 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 core = require('web.core');
var Sidebar = require('web.Sidebar'); var Sidebar = require('web.Sidebar');
var ActionManager = require('web.ActionManager'); var ActionManager = require('web.ActionManager');
var Context = require('web.Context');
var pyeval = require('web.pyeval');
var _t = core._t, var _t = core._t,
QWeb = core.qweb; QWeb = core.qweb;
Sidebar.include({ Sidebar.include({
redraw: function() { _redraw: function () {
var self = this; var self = this;
this._super.apply(this, arguments); this._super.apply(this, arguments);
self.$el.find("a[href]").attr('target', '_blank'); 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
self.$el.find('.oe_sidebar_add_url').on('click', function (e) { .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(); self.on_url_doc();
}); });
}, },
on_url_doc: function() { on_url_doc: function (event) {
var self = this; var self = this;
var env = self.env
var view = self.getParent(); var view = self.getParent();
var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; var ids = self.env.activeIds;
if( !_.isEmpty(ids) ){ if (!_.isEmpty(ids)) {
view.sidebar_eval_context().done(function (context) { var activeIdsContext = {
self.rpc("/web/action/load", { action_id: "document_url.action_ir_attachment_add_url" }).done(function(result) { active_id: env.activeIds[0],
self.getParent().do_action(result, { active_ids: env.activeIds,
additional_context: { active_model: env.model,
'active_ids': ids, };
'active_id': [ids[0]], if (env.domain) {
'active_model': view.dataset.model, 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,
},
}); });
}); });
} }

View File

@ -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;
}
}

View File

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

View File

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_document_url

View File

@ -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)

View File

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

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>) # © 2016 ACSONE SA/NV (<http://acsone.eu>)

View File

@ -1,42 +1,32 @@
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>) # © 2016 ACSONE SA/NV (<http://acsone.eu>)
from openerp.osv import fields, orm from odoo import fields, models
try: from urllib import parse
# Python 3
from urllib import parse as urlparse
except:
from urlparse import urlparse
class AddUrlWizard(orm.TransientModel): class AddUrlWizard(models.Model):
_name = 'ir.attachment.add_url' _name = 'ir.attachment.add_url'
_columns = { name = fields.Char('Name', required=True)
'name': fields.char('Name', required=True), url = fields.Char('URL', 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.""" """Adds the URL with the given name as an ir.attachment record."""
if context is None: if not self.env.context.get('active_model'):
context = {}
if not context.get('active_model'):
return return
attachment_obj = self.pool['ir.attachment'] attachment_obj = self.env['ir.attachment']
for form in self.browse(cr, uid, ids, context=context): for form in self:
url = urlparse(form.url) url = parse.urlparse(form.url)
if not url.scheme: if not url.scheme:
url = urlparse('%s%s' % ('http://', form.url)) url = parse.urlparse('%s%s' % ('http://', form.url))
for active_id in context.get('active_ids', []): for active_id in self.env.context.get('active_ids', []):
attachment = { attachment = {
'name': form.name, 'name': form.name,
'type': 'url', 'type': 'url',
'url': url.geturl(), 'url': url.geturl(),
'user_id': uid,
'res_id': active_id, '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'} return {'type': 'ir.actions.act_close_wizard_and_reload_view'}