diff --git a/report_qweb_parameter/__init__.py b/report_qweb_parameter/__init__.py index b44d7659..31660d6a 100644 --- a/report_qweb_parameter/__init__.py +++ b/report_qweb_parameter/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import models diff --git a/report_qweb_parameter/__manifest__.py b/report_qweb_parameter/__manifest__.py index 28904594..ec86cd92 100644 --- a/report_qweb_parameter/__manifest__.py +++ b/report_qweb_parameter/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Creu Blanca # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). @@ -10,15 +9,10 @@ Add new parameters for qweb templates in order to reduce field length and check minimal length """, - "author": "Creu Blanca," - "Odoo Community Association (OCA)", + "author": "Creu Blanca," "Odoo Community Association (OCA)", "website": "https://github.com/oca/reporting-engine", "category": "Technical Settings", - "depends": [ - "web", - ], - "demo": [ - "demo/test_report_field_length.xml" - ], + "depends": ["web"], + "demo": ["demo/test_report_field_length.xml"], "installable": True, } diff --git a/report_qweb_parameter/demo/test_report_field_length.xml b/report_qweb_parameter/demo/test_report_field_length.xml index 2b127431..f5293616 100644 --- a/report_qweb_parameter/demo/test_report_field_length.xml +++ b/report_qweb_parameter/demo/test_report_field_length.xml @@ -1,25 +1,40 @@ - + - - diff --git a/report_qweb_parameter/models/__init__.py b/report_qweb_parameter/models/__init__.py index dd58c12a..3abf9999 100644 --- a/report_qweb_parameter/models/__init__.py +++ b/report_qweb_parameter/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import ir_qweb diff --git a/report_qweb_parameter/models/ir_qweb.py b/report_qweb_parameter/models/ir_qweb.py index 67e80044..5d110acf 100644 --- a/report_qweb_parameter/models/ir_qweb.py +++ b/report_qweb_parameter/models/ir_qweb.py @@ -1,47 +1,53 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Creu Blanca # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import models, _ +from odoo import _, models from odoo.exceptions import ValidationError class IrQWeb(models.AbstractModel): - _inherit = 'ir.qweb' + _inherit = "ir.qweb" @staticmethod def check_length(value, min_length=False, max_length=False): if min_length and len(value) < min_length: - raise ValidationError( - _('Length cannot be less than %s') % str(min_length)) + raise ValidationError(_("Length cannot be less than %s") % str(min_length)) if max_length and len(value) > max_length: - raise ValidationError( - _('Length cannot be more than %s') % str(max_length)) + raise ValidationError(_("Length cannot be more than %s") % str(max_length)) return value def _compile_directive_esc(self, el, options): - min_value = el.attrib.pop('t-minlength', False) - max_value = el.attrib.pop('t-maxlength', False) + min_value = el.attrib.pop("t-minlength", False) + max_value = el.attrib.pop("t-maxlength", False) if min_value or max_value: - el.attrib['t-esc'] = 'docs.env["ir.qweb"].check_length(' + \ - el.attrib['t-esc'] + ', ' + \ - (min_value or 'False') + ', ' + \ - (max_value or 'False') + ')' - if 't-length' in el.attrib: - length = el.attrib.pop('t-length') - el.attrib['t-esc'] = '(' + el.attrib[ - 't-esc'] + ')[:' + length + ']' + el.attrib["t-esc"] = ( + 'docs.env["ir.qweb"].check_length(' + + el.attrib["t-esc"] + + ", " + + (min_value or "False") + + ", " + + (max_value or "False") + + ")" + ) + if "t-length" in el.attrib: + length = el.attrib.pop("t-length") + el.attrib["t-esc"] = "(" + el.attrib["t-esc"] + ")[:" + length + "]" return super(IrQWeb, self)._compile_directive_esc(el, options) def _compile_directive_raw(self, el, options): - min_value = el.attrib.pop('t-minlength', False) - max_value = el.attrib.pop('t-maxlength', False) + min_value = el.attrib.pop("t-minlength", False) + max_value = el.attrib.pop("t-maxlength", False) if min_value or max_value: - el.attrib['t-raw'] = 'docs.env["ir.qweb"].check_length(' + \ - el.attrib['t-raw'] + ', ' + \ - (min_value or 'False') + ', ' + \ - (max_value or 'False') + ')' - if 't-length' in el.attrib: - length = el.attrib.pop('t-length') - el.attrib['t-raw'] = el.attrib['t-raw'] + '[:' + length + ']' + el.attrib["t-raw"] = ( + 'docs.env["ir.qweb"].check_length(' + + el.attrib["t-raw"] + + ", " + + (min_value or "False") + + ", " + + (max_value or "False") + + ")" + ) + if "t-length" in el.attrib: + length = el.attrib.pop("t-length") + el.attrib["t-raw"] = el.attrib["t-raw"] + "[:" + length + "]" return super(IrQWeb, self)._compile_directive_raw(el, options) diff --git a/report_qweb_parameter/tests/__init__.py b/report_qweb_parameter/tests/__init__.py index e6422248..62db47d0 100644 --- a/report_qweb_parameter/tests/__init__.py +++ b/report_qweb_parameter/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import test_report_qweb_parameter diff --git a/report_qweb_parameter/tests/test_report_qweb_parameter.py b/report_qweb_parameter/tests/test_report_qweb_parameter.py index 77e2b754..82ae7458 100644 --- a/report_qweb_parameter/tests/test_report_qweb_parameter.py +++ b/report_qweb_parameter/tests/test_report_qweb_parameter.py @@ -1,39 +1,40 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Creu Blanca # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import xml.etree.ElementTree as ET -from odoo.addons.base.models.qweb import QWebException from odoo.tests import common +from odoo.addons.base.models.qweb import QWebException + class TestReportQWebParameter(common.TransactionCase): def test_qweb_parameter(self): - report_name = 'report_qweb_parameter.test_report_length' - report_obj = self.env['ir.actions.report'] + report_name = "report_qweb_parameter.test_report_length" + report_obj = self.env["ir.actions.report"] report_object = report_obj._get_report_from_name(report_name) - docs = self.env['res.company'].create({ - 'name': 'Test company', - 'street': '12345678901', - 'vat': '12345678901', - 'company_registry': '1234567890' - }) - docs.website = '1234567890' # for avoding that Odoo adds http:// + docs = self.env["res.company"].create( + { + "name": "Test company", + "street": "12345678901", + "vat": "12345678901", + "company_registry": "1234567890", + } + ) + docs.website = "1234567890" # for avoding that Odoo adds http:// rep = report_object.render(docs.ids, False) root = ET.fromstring(rep[0]) self.assertEqual(root[0].text, "1234567890") self.assertEqual(root[2].text, "1234567890") - docs.update({'street': '123456789'}) + docs.update({"street": "123456789"}) with self.assertRaises(QWebException): report_object.render(docs.ids, False) - docs.update({'street': '1234567890', 'vat': '123456789'}) + docs.update({"street": "1234567890", "vat": "123456789"}) with self.assertRaises(QWebException): report_object.render(docs.ids, False) - docs.update({'vat': '1234567890', 'website': '12345678901'}) + docs.update({"vat": "1234567890", "website": "12345678901"}) with self.assertRaises(QWebException): report_object.render(docs.ids, False) - docs.update( - {'website': '1234567890', 'company_registry': '12345678901'}) + docs.update({"website": "1234567890", "company_registry": "12345678901"}) with self.assertRaises(QWebException): report_object.render(docs.ids, False)