[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
==============
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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 <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**>`_.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`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
=======
Authors
~~~~~~~
* Tecnativa
Contributors
------------
~~~~~~~~~~~~
* 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
: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 <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)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>)

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
{
'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',

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

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"?>
<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>
<t t-name="AddUrlDocumentItem">
<li class="o_sidebar_add_url">
<span>Add URL...</span>
</li>
</t>
</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"?>
<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>
</xpath>
</template>
<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>
<link rel="stylesheet" type="text/less" href="/document_url/static/src/less/url.less"/>
</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.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>
<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">
<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>
</odoo>

View File

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

View File

@ -1,42 +1,32 @@
# -*- coding: utf-8 -*-
# © 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
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'}