[MIG] report_qweb_parameter: Migration to 16.0
parent
2a81bda49c
commit
f9b7ae5afa
|
@ -3,7 +3,7 @@
|
|||
|
||||
{
|
||||
"name": "Report QWeb Parameter",
|
||||
"version": "15.0.1.0.0",
|
||||
"version": "16.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"summary": """
|
||||
Add new parameters for qweb templates in order to reduce field length
|
||||
|
|
|
@ -34,6 +34,19 @@
|
|||
t-raw="docs[0].company_registry"
|
||||
t-if="docs[0].company_registry"
|
||||
/>
|
||||
<li
|
||||
name="raw_length"
|
||||
t-minlength="10"
|
||||
t-length="10"
|
||||
t-out="docs[0].vat"
|
||||
t-if="docs[0].vat"
|
||||
/>
|
||||
<li
|
||||
name="raw_maxlength"
|
||||
t-maxlength="10"
|
||||
t-out="docs[0].company_registry"
|
||||
t-if="docs[0].company_registry"
|
||||
/>
|
||||
</data>
|
||||
</template>
|
||||
</odoo>
|
||||
|
|
|
@ -16,7 +16,7 @@ class IrQWeb(models.AbstractModel):
|
|||
raise ValidationError(_("Length cannot be more than %s") % str(max_length))
|
||||
return value
|
||||
|
||||
def _compile_directive_esc(self, el, options, indent):
|
||||
def _compile_directive_esc(self, el, compile_context, level):
|
||||
min_value = el.attrib.pop("t-minlength", False)
|
||||
max_value = el.attrib.pop("t-maxlength", False)
|
||||
if min_value or max_value:
|
||||
|
@ -32,9 +32,28 @@ class IrQWeb(models.AbstractModel):
|
|||
if "t-length" in el.attrib:
|
||||
tlength = el.attrib.pop("t-length")
|
||||
el.attrib["t-esc"] = "(" + el.attrib["t-esc"] + ")[:" + tlength + "]"
|
||||
return super()._compile_directive_esc(el, options, indent)
|
||||
return super()._compile_directive_esc(el, compile_context, level)
|
||||
|
||||
def _compile_directive_raw(self, el, options, indent):
|
||||
def _compile_directive_out(self, el, compile_context, level):
|
||||
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-out"] = (
|
||||
'docs.env["ir.qweb"].check_length('
|
||||
+ el.attrib["t-out"]
|
||||
+ ", "
|
||||
+ (min_value or "False")
|
||||
+ ", "
|
||||
+ (max_value or "False")
|
||||
+ ")"
|
||||
)
|
||||
if "t-length" in el.attrib:
|
||||
tlength = el.attrib.pop("t-length")
|
||||
el.attrib["t-out"] = el.attrib["t-out"] + "[:" + tlength + "]"
|
||||
return super()._compile_directive_out(el, compile_context, level)
|
||||
|
||||
def _compile_directive_raw(self, el, compile_context, level):
|
||||
# TODO: t-raw is deprecated, can it be removed?
|
||||
min_value = el.attrib.pop("t-minlength", False)
|
||||
max_value = el.attrib.pop("t-maxlength", False)
|
||||
if min_value or max_value:
|
||||
|
@ -50,4 +69,4 @@ class IrQWeb(models.AbstractModel):
|
|||
if "t-length" in el.attrib:
|
||||
tlength = el.attrib.pop("t-length")
|
||||
el.attrib["t-raw"] = el.attrib["t-raw"] + "[:" + tlength + "]"
|
||||
return super()._compile_directive_raw(el, options, indent)
|
||||
return super()._compile_directive_raw(el, compile_context, level)
|
||||
|
|
|
@ -5,14 +5,14 @@ import xml.etree.ElementTree as ET
|
|||
|
||||
from odoo.tests import common
|
||||
|
||||
from odoo.addons.base.models.qweb import QWebException
|
||||
from odoo.addons.base.models.ir_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_object = report_obj._get_report_from_name(report_name)
|
||||
report_object = report_obj
|
||||
docs = self.env["res.company"].create(
|
||||
{
|
||||
"name": "Test company",
|
||||
|
@ -22,19 +22,20 @@ class TestReportQWebParameter(common.TransactionCase):
|
|||
}
|
||||
)
|
||||
docs.website = "1234567890" # for avoding that Odoo adds http://
|
||||
rep = report_object._render(docs.ids, False)
|
||||
rep = report_object._render(report_name, docs.ids, False)
|
||||
root = ET.fromstring(rep[0])
|
||||
self.assertEqual(root[0].text, "1234567890")
|
||||
self.assertEqual(root[2].text, "1234567890")
|
||||
self.assertEqual(root[4].text, "1234567890")
|
||||
docs.update({"street": "123456789"})
|
||||
with self.assertRaises(QWebException):
|
||||
report_object._render(docs.ids, False)
|
||||
report_object._render(report_name, docs.ids, False)
|
||||
docs.update({"street": "1234567890", "vat": "123456789"})
|
||||
with self.assertRaises(QWebException):
|
||||
report_object._render(docs.ids, False)
|
||||
report_object._render(report_name, docs.ids, False)
|
||||
docs.update({"vat": "1234567890", "website": "12345678901"})
|
||||
with self.assertRaises(QWebException):
|
||||
report_object._render(docs.ids, False)
|
||||
report_object._render(report_name, docs.ids, False)
|
||||
docs.update({"website": "1234567890", "company_registry": "12345678901"})
|
||||
with self.assertRaises(QWebException):
|
||||
report_object._render(docs.ids, False)
|
||||
report_object._render(report_name, docs.ids, False)
|
||||
|
|
Loading…
Reference in New Issue