diff --git a/report_qweb_parameter/README.rst b/report_qweb_parameter/README.rst new file mode 100644 index 0000000000..d3a4b66474 --- /dev/null +++ b/report_qweb_parameter/README.rst @@ -0,0 +1,110 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +===================== +Report QWeb Parameter +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ed0bcdb6b645a340d55224826deb94367c4596a1f5fed4011149c6ea0d925ef9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Freporting--engine-lightgray.png?logo=github + :target: https://github.com/OCA/reporting-engine/tree/19.0/report_qweb_parameter + :alt: OCA/reporting-engine +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/reporting-engine-19-0/reporting-engine-19-0-report_qweb_parameter + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to add new parameters on QWeb reports. Currently, +we have defined a field maximum on a report and a validation of maximal +and minimal size. It is useful on xml reports in order to validate +length. XML are sometimes XSD dependant and we must validate its format. +For example, in spanish facturae +(http://www.facturae.gob.es/Paginas/Index.aspx), where length and format +must be validated in several fields in order to send an invoice. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Add a t-length attribute on report templates fields that will + truncate the field +2. Add a t-minlength attribute on report template fields that will check + the min length +3. Add a t-maxlength attribute on report template fields that will check + the max length + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Creu Blanca + +Contributors +------------ + +- Enric Tobella + +- `Tecnativa `__: + + - Carlos Roca + +- Iván Antón + +- `Sygel Technology `__: + + - Valentin Vinagre + +- `Studio73 `__: + + - Alex Garcia + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/reporting-engine `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/report_qweb_parameter/__init__.py b/report_qweb_parameter/__init__.py new file mode 100644 index 0000000000..31660d6a96 --- /dev/null +++ b/report_qweb_parameter/__init__.py @@ -0,0 +1,3 @@ +# 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 new file mode 100644 index 0000000000..71e1c82025 --- /dev/null +++ b/report_qweb_parameter/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2017 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Report QWeb Parameter", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "summary": """ + Add new parameters for qweb templates in order to reduce field length + and check minimal length + """, + "author": "Creu Blanca, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/reporting-engine", + "category": "Technical Settings", + "depends": ["web"], + "installable": True, +} diff --git a/report_qweb_parameter/i18n/ca.po b/report_qweb_parameter/i18n/ca.po new file mode 100644 index 0000000000..a116902932 --- /dev/null +++ b/report_qweb_parameter/i18n/ca.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_parameter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-06-15 18:05+0000\n" +"Last-Translator: jabelchi \n" +"Language-Team: none\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: report_qweb_parameter +#: model:ir.actions.report,name:report_qweb_parameter.test_report_length_report_id +msgid "Length Report" +msgstr "Longitud de l'informe" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be less than %s" +msgstr "La longitut no pot ser menor que %s" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be more than %s" +msgstr "La llargada no pot ser més gran que %s" + +#. module: report_qweb_parameter +#: model:ir.model,name:report_qweb_parameter.model_ir_qweb +msgid "Qweb" +msgstr "Qweb" diff --git a/report_qweb_parameter/i18n/es.po b/report_qweb_parameter/i18n/es.po new file mode 100644 index 0000000000..060c57c729 --- /dev/null +++ b/report_qweb_parameter/i18n/es.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_parameter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: Carlos \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" + +#. module: report_qweb_parameter +#: model:ir.actions.report,name:report_qweb_parameter.test_report_length_report_id +msgid "Length Report" +msgstr "Longitud del informe" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be less than %s" +msgstr "La longitud no puede ser menor a %s" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be more than %s" +msgstr "La longitud no puede ser mayor a %s" + +#. module: report_qweb_parameter +#: model:ir.model,name:report_qweb_parameter.model_ir_qweb +msgid "Qweb" +msgstr "Qweb" diff --git a/report_qweb_parameter/i18n/fr.po b/report_qweb_parameter/i18n/fr.po new file mode 100644 index 0000000000..3ae4e02222 --- /dev/null +++ b/report_qweb_parameter/i18n/fr.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_parameter +# +# Translators: +# Nicolas JEUDY , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-05 17:53+0000\n" +"PO-Revision-Date: 2018-01-05 17:53+0000\n" +"Last-Translator: Nicolas JEUDY , 2018\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: report_qweb_parameter +#: model:ir.actions.report,name:report_qweb_parameter.test_report_length_report_id +msgid "Length Report" +msgstr "Longueur du rapport " + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be less than %s" +msgstr "La longueur du rapport ne peut pas être inférieure à %s" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be more than %s" +msgstr "La longueur du rapport ne peut pas être supérieure à %s" + +#. module: report_qweb_parameter +#: model:ir.model,name:report_qweb_parameter.model_ir_qweb +msgid "Qweb" +msgstr "" + +#~ msgid "ir.qweb" +#~ msgstr "ir.qweb" diff --git a/report_qweb_parameter/i18n/it.po b/report_qweb_parameter/i18n/it.po new file mode 100644 index 0000000000..451cb2d322 --- /dev/null +++ b/report_qweb_parameter/i18n/it.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_parameter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-11-20 23:36+0000\n" +"Last-Translator: Alessandro Fiorino \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: report_qweb_parameter +#: model:ir.actions.report,name:report_qweb_parameter.test_report_length_report_id +msgid "Length Report" +msgstr "Lunghezza Report" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be less than %s" +msgstr "La lunghezza non può essere meno di %s" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be more than %s" +msgstr "La lunghezza non può essere più di %s" + +#. module: report_qweb_parameter +#: model:ir.model,name:report_qweb_parameter.model_ir_qweb +msgid "Qweb" +msgstr "Qweb" diff --git a/report_qweb_parameter/i18n/pt.po b/report_qweb_parameter/i18n/pt.po new file mode 100644 index 0000000000..8456f83da7 --- /dev/null +++ b/report_qweb_parameter/i18n/pt.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_parameter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-08-14 13:44+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.7.1\n" + +#. module: report_qweb_parameter +#: model:ir.actions.report,name:report_qweb_parameter.test_report_length_report_id +msgid "Length Report" +msgstr "Relatório de Comprimento" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be less than %s" +msgstr "Comprimento não pode ser superior a %s" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +#, python-format +msgid "Length cannot be more than %s" +msgstr "Comprimento não pode ser inferior a %s" + +#. module: report_qweb_parameter +#: model:ir.model,name:report_qweb_parameter.model_ir_qweb +msgid "Qweb" +msgstr "" diff --git a/report_qweb_parameter/i18n/report_qweb_parameter.pot b/report_qweb_parameter/i18n/report_qweb_parameter.pot new file mode 100644 index 0000000000..4cdaf62335 --- /dev/null +++ b/report_qweb_parameter/i18n/report_qweb_parameter.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_parameter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: report_qweb_parameter +#: model:ir.actions.report,name:report_qweb_parameter.test_report_length_report_id +msgid "Length Report" +msgstr "" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +msgid "Length cannot be less than %s" +msgstr "" + +#. module: report_qweb_parameter +#. odoo-python +#: code:addons/report_qweb_parameter/models/ir_qweb.py:0 +msgid "Length cannot be more than %s" +msgstr "" + +#. module: report_qweb_parameter +#: model:ir.model,name:report_qweb_parameter.model_ir_qweb +msgid "Qweb" +msgstr "" diff --git a/report_qweb_parameter/models/__init__.py b/report_qweb_parameter/models/__init__.py new file mode 100644 index 0000000000..3abf9999a5 --- /dev/null +++ b/report_qweb_parameter/models/__init__.py @@ -0,0 +1,3 @@ +# 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 new file mode 100644 index 0000000000..c77d946199 --- /dev/null +++ b/report_qweb_parameter/models/ir_qweb.py @@ -0,0 +1,76 @@ +# Copyright 2017 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.exceptions import ValidationError + + +class IrQWeb(models.AbstractModel): + _inherit = "ir.qweb" + + def check_length(self, value, min_length=False, max_length=False): # noqa + """No use staticmethod because self is needed to translate exception messages""" + if min_length and len(value) < min_length: + raise ValidationError( + self.env._("Length cannot be less than %s", min_length) + ) + if max_length and len(value) > max_length: + raise ValidationError( + self.env._("Length cannot be more than %s", max_length) + ) + return value + + 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: + 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: + tlength = el.attrib.pop("t-length") + el.attrib["t-esc"] = "(" + el.attrib["t-esc"] + ")[:" + tlength + "]" + return super()._compile_directive_esc(el, compile_context, level) + + 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: + 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: + tlength = el.attrib.pop("t-length") + el.attrib["t-raw"] = "(" + el.attrib["t-raw"] + ")[:" + tlength + "]" + return super()._compile_directive_raw(el, compile_context, level) diff --git a/report_qweb_parameter/pyproject.toml b/report_qweb_parameter/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/report_qweb_parameter/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/report_qweb_parameter/readme/CONTRIBUTORS.md b/report_qweb_parameter/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..8193eaf75c --- /dev/null +++ b/report_qweb_parameter/readme/CONTRIBUTORS.md @@ -0,0 +1,15 @@ +- Enric Tobella \<\> + +- [Tecnativa](https://www.tecnativa.com): + + > - Carlos Roca + +- Iván Antón \<\> + +- [Sygel Technology](https://www.sygel.es): + + > - Valentin Vinagre + +- [Studio73](https://www.studio73.es): + + > - Alex Garcia diff --git a/report_qweb_parameter/readme/DESCRIPTION.md b/report_qweb_parameter/readme/DESCRIPTION.md new file mode 100644 index 0000000000..503e8234b6 --- /dev/null +++ b/report_qweb_parameter/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module allows you to add new parameters on QWeb reports. Currently, +we have defined a field maximum on a report and a validation of maximal +and minimal size. It is useful on xml reports in order to validate +length. XML are sometimes XSD dependant and we must validate its format. +For example, in spanish facturae +(), where length and +format must be validated in several fields in order to send an invoice. diff --git a/report_qweb_parameter/readme/USAGE.md b/report_qweb_parameter/readme/USAGE.md new file mode 100644 index 0000000000..49f8f54143 --- /dev/null +++ b/report_qweb_parameter/readme/USAGE.md @@ -0,0 +1,6 @@ +1. Add a t-length attribute on report templates fields that will + truncate the field +2. Add a t-minlength attribute on report template fields that will + check the min length +3. Add a t-maxlength attribute on report template fields that will + check the max length diff --git a/report_qweb_parameter/static/description/icon.png b/report_qweb_parameter/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/report_qweb_parameter/static/description/icon.png differ diff --git a/report_qweb_parameter/static/description/index.html b/report_qweb_parameter/static/description/index.html new file mode 100644 index 0000000000..458e94cba0 --- /dev/null +++ b/report_qweb_parameter/static/description/index.html @@ -0,0 +1,471 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Report QWeb Parameter

+ +

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runboat

+

This module allows you to add new parameters on QWeb reports. Currently, +we have defined a field maximum on a report and a validation of maximal +and minimal size. It is useful on xml reports in order to validate +length. XML are sometimes XSD dependant and we must validate its format. +For example, in spanish facturae +(http://www.facturae.gob.es/Paginas/Index.aspx), where length and format +must be validated in several fields in order to send an invoice.

+

Table of contents

+ +
+

Usage

+
    +
  1. Add a t-length attribute on report templates fields that will +truncate the field
  2. +
  3. Add a t-minlength attribute on report template fields that will check +the min length
  4. +
  5. Add a t-maxlength attribute on report template fields that will check +the max length
  6. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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/reporting-engine project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/report_qweb_parameter/tests/__init__.py b/report_qweb_parameter/tests/__init__.py new file mode 100644 index 0000000000..62db47d0f9 --- /dev/null +++ b/report_qweb_parameter/tests/__init__.py @@ -0,0 +1,3 @@ +# 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 new file mode 100644 index 0000000000..9dfae5eae4 --- /dev/null +++ b/report_qweb_parameter/tests/test_report_qweb_parameter.py @@ -0,0 +1,122 @@ +# Copyright 2017 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import xml.etree.ElementTree as ET + +from odoo.exceptions import ValidationError +from odoo.tests import common + + +class TestReportQWebParameter(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.report_name = "test_report_length" + cls.full_report_name = f"report_qweb_parameter.{cls.report_name}" + cls.view = cls.env["ir.ui.view"].create( + { + "name": cls.report_name, + "type": "qweb", + "arch": """ + +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • + + """, + } + ) + cls.report = cls.env["ir.actions.report"].create( + { + "name": "Length Report", + "model": "res.company", + "report_type": "qweb-html", + "report_name": cls.full_report_name, + } + ) + cls.env["ir.model.data"].create( + [ + { + "module": "report_qweb_parameter", + "name": cls.report_name, + "model": "ir.ui.view", + "res_id": cls.view.id, + }, + { + "module": "report_qweb_parameter", + "name": "test_report_length_report", + "model": "ir.actions.report", + "res_id": cls.report.id, + }, + ] + ) + + def test_qweb_parameter(self): + docs = self.env["res.company"].create( + { + "name": "Test company", + "street": "12345678901", + "vat": "12345678901", + "company_registry": "1234567890", + } + ) + docs.website = "1234567890" + rep = self.report._render(self.full_report_name, docs.ids, False) + root = ET.fromstring(rep[0]) + + # test length + self.assertEqual(root[0].text, "1234567890") + self.assertEqual(root[3].text, "1234567890") + self.assertEqual(root[6].text, "1234567890") + + # test conditional length + self.assertEqual(root[1].text, "Tes") + self.assertEqual(root[4].text, "Test") + self.assertEqual(root[7].text, "Test ") + + # test maxlength + docs.update({"street": "123456789"}) + with self.assertRaises(ValidationError): + self.report._render(self.full_report_name, docs.ids, False) + docs.update({"street": "1234567890", "vat": "123456789"}) + with self.assertRaises(ValidationError): + self.report._render(self.full_report_name, docs.ids, False) + docs.update({"vat": "1234567890", "website": "12345678901"}) + with self.assertRaises(ValidationError): + self.report._render(self.full_report_name, docs.ids, False) + docs.update({"website": "1234567890", "company_registry": "12345678901"}) + with self.assertRaises(ValidationError): + self.report._render(self.full_report_name, docs.ids, False)