[IMP] report_qweb_parameter: black, isort, prettier
parent
0b8cfdc299
commit
de6c4e3e38
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -1,25 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<report
|
||||
id="test_report_length_report_id"
|
||||
model="res.company"
|
||||
string="Length Report"
|
||||
report_type="qweb-html"
|
||||
name="report_qweb_parameter.test_report_length"
|
||||
id="test_report_length_report_id"
|
||||
model="res.company"
|
||||
string="Length Report"
|
||||
report_type="qweb-html"
|
||||
name="report_qweb_parameter.test_report_length"
|
||||
/>
|
||||
|
||||
<template id="test_report_length">
|
||||
<data>
|
||||
<li name="esc_length" t-minlength="10" t-length="10"
|
||||
t-esc="docs[0].street" t-if="docs[0].street"/>
|
||||
<li name="esc_maxlength" t-maxlength="10"
|
||||
t-esc="docs[0].website" t-if="docs[0].website"/>
|
||||
<li name="raw_length" t-minlength="10" t-length="10"
|
||||
t-raw="docs[0].vat" t-if="docs[0].vat"/>
|
||||
<li name="raw_maxlength" t-maxlength="10"
|
||||
<li
|
||||
name="esc_length"
|
||||
t-minlength="10"
|
||||
t-length="10"
|
||||
t-esc="docs[0].street"
|
||||
t-if="docs[0].street"
|
||||
/>
|
||||
<li
|
||||
name="esc_maxlength"
|
||||
t-maxlength="10"
|
||||
t-esc="docs[0].website"
|
||||
t-if="docs[0].website"
|
||||
/>
|
||||
<li
|
||||
name="raw_length"
|
||||
t-minlength="10"
|
||||
t-length="10"
|
||||
t-raw="docs[0].vat"
|
||||
t-if="docs[0].vat"
|
||||
/>
|
||||
<li
|
||||
name="raw_maxlength"
|
||||
t-maxlength="10"
|
||||
t-raw="docs[0].company_registry"
|
||||
t-if="docs[0].company_registry"/>
|
||||
t-if="docs[0].company_registry"
|
||||
/>
|
||||
</data>
|
||||
</template>
|
||||
</odoo>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import ir_qweb
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue