[IMP] document_url: black, isort

This commit is contained in:
Manuel Calero 2020-03-11 10:28:27 +01:00 committed by Bhavesh Heliconia
parent 0211bf41c2
commit 9260841adf
6 changed files with 47 additions and 61 deletions

View File

@ -1,23 +1,15 @@
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2020 Tecnativa - Manuel Calero
{ {
'name': 'URL attachment', "name": "URL attachment",
'version': '12.0.1.0.0', "version": "13.0.1.0.0",
'category': 'Tools', "category": "Tools",
'author': "Tecnativa," "author": "Tecnativa," "Odoo Community Association (OCA)",
"Odoo Community Association (OCA)", "website": "https://github.com/OCA/knowledge",
'website': 'https://github.com/OCA/knowledge', "license": "AGPL-3",
'license': 'AGPL-3', "data": ["view/document_url_view.xml", "security/ir.model.access.csv"],
'depends': [ "qweb": ["static/src/xml/url.xml"],
'document', "installable": True,
],
'data': [
'view/document_url_view.xml',
'security/ir.model.access.csv',
],
'qweb': [
'static/src/xml/url.xml',
],
'installable': True,
} }

View File

@ -3,3 +3,4 @@
* Pedro M. Baeza * Pedro M. Baeza
* Ernesto Tejeda * Ernesto Tejeda
* Manuel Calero

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/12.0/document_url"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-12-0/knowledge-12-0-document_url"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/13.0/document_url"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-12-0/knowledge-12-0-document_url"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Module that allows to attach an URL as a document.</p> <p>Module that allows to attach an URL as a document.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
@ -399,7 +399,7 @@ the object.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>.
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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -428,7 +428,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/12.0/document_url">OCA/knowledge</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/13.0/document_url">OCA/knowledge</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -2,6 +2,7 @@
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> * Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) * Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
* Copyright 2019 Tecnativa - Ernesto Tejeda * Copyright 2019 Tecnativa - Ernesto Tejeda
* Copyright 2020 Tecnativa - Manuel Calero
* 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) {
@ -13,13 +14,8 @@ odoo.define('document_url', function (require) {
events: _.extend(AttachmentBox.prototype.events, { events: _.extend(AttachmentBox.prototype.events, {
"click span.o_add_url_button": "_onAddUrl", "click span.o_add_url_button": "_onAddUrl",
}), }),
/** _onAddUrl: function () {
* Opens wizard to add an URL attachment to the current record // Opens wizard to add an URL attachment to the current record
*
* @private
* @param {MouseEvent} ev
*/
_onAddUrl: function (ev) {
this.do_action('document_url.action_ir_attachment_add_url', { this.do_action('document_url.action_ir_attachment_add_url', {
additional_context: { additional_context: {
'active_id': this.currentResID, 'active_id': this.currentResID,
@ -29,11 +25,8 @@ odoo.define('document_url', function (require) {
on_close: this._onAddedUrl.bind(this), on_close: this._onAddedUrl.bind(this),
}); });
}, },
/**
* @private
*/
_onAddedUrl: function () { _onAddedUrl: function () {
this.trigger_up('reload_attachment_box'); this.trigger_up('reload_attachment_box');
} },
}); });
}); });

View File

@ -6,25 +6,24 @@ from odoo.tests import common
class TestDocumentUrl(common.TransactionCase): class TestDocumentUrl(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestDocumentUrl, self).setUp() super(TestDocumentUrl, self).setUp()
wizard_add_url = self.env['ir.attachment.add_url'] wizard_add_url = self.env["ir.attachment.add_url"]
ctx = { ctx = {
'active_model': 'res.users', "active_model": "res.users",
'active_id': self.env.ref('base.user_demo').id, "active_id": self.env.ref("base.user_demo").id,
'active_ids': [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({ self.wizard_add_url = wizard_add_url.with_context(ctx).create(
'name': 'Demo User (Website)', {"name": "Demo User (Website)", "url": "http://www.odoodemouser.com"}
'url': 'http://www.odoodemouser.com' )
})
def test_add_url_attachment(self): def test_add_url_attachment(self):
self.wizard_add_url.action_add_url() self.wizard_add_url.action_add_url()
domain = [ domain = [
('type', '=', 'url'), ("type", "=", "url"),
('name', '=', 'Demo User (Website)'), ("name", "=", "Demo User (Website)"),
('url', '=', 'http://www.odoodemouser.com'), ("url", "=", "http://www.odoodemouser.com"),
('res_model', '=', 'res.users'), ("res_model", "=", "res.users"),
('res_id', '=', self.env.ref('base.user_demo').id) ("res_id", "=", self.env.ref("base.user_demo").id),
] ]
attachment_added_count = self.env['ir.attachment'].search_count(domain) attachment_added_count = self.env["ir.attachment"].search_count(domain)
self.assertEqual(attachment_added_count, 1) self.assertEqual(attachment_added_count, 1)

View File

@ -1,33 +1,34 @@
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
from odoo import fields, models
from urllib import parse from urllib import parse
from odoo import fields, models
class AddUrlWizard(models.Model): class AddUrlWizard(models.Model):
_name = 'ir.attachment.add_url' _name = "ir.attachment.add_url"
_description = 'Wizard to add URL attachment' _description = "Wizard to add URL attachment"
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): 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 not self.env.context.get('active_model'): if not self.env.context.get("active_model"):
return return
attachment_obj = self.env['ir.attachment'] attachment_obj = self.env["ir.attachment"]
for form in self: for form in self:
url = parse.urlparse(form.url) url = parse.urlparse(form.url)
if not url.scheme: if not url.scheme:
url = parse.urlparse('%s%s' % ('http://', form.url)) url = parse.urlparse("{}{}".format("http://", form.url))
for active_id in self.env.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(),
'res_id': active_id, "res_id": active_id,
'res_model': self.env.context['active_model'], "res_model": self.env.context["active_model"],
} }
attachment_obj.create(attachment) attachment_obj.create(attachment)
return {'type': 'ir.actions.act_window_close'} return {"type": "ir.actions.act_window_close"}