-
-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
===================== | ||
Report QWeb Parameter | ||
===================== | ||
|
||
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. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
#. Add a t-length attribute on report templates fields that will truncate the field | ||
#. Add a t-minlength attribute on report template fields that will check the min length | ||
#. Add a t-maxlength attribute on report template fields that will check the max length | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/143/11.0 | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/reporting-engine/issues>`_. 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 feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Enric Tobella <etobella@creublanca.es> | ||
|
||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Creu Blanca | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Report QWeb Parameter", | ||
"version": "11.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", | ||
], | ||
"demo": [ | ||
"demo/test_report_field_length.xml" | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?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" | ||
/> | ||
|
||
<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" | ||
t-raw="docs[0].company_registry" | ||
t-if="docs[0].company_registry"/> | ||
</data> | ||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * report_qweb_parameter | ||
# | ||
# Translators: | ||
# Nicolas JEUDY <njeudy@panda-chi.io>, 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 <njeudy@panda-chi.io>, 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 | ||
#: code:addons/report_qweb_parameter/models/ir_qweb.py:16 | ||
#, 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 | ||
#: code:addons/report_qweb_parameter/models/ir_qweb.py:19 | ||
#, 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 "ir.qweb" | ||
msgstr "ir.qweb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * report_qweb_parameter | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.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 | ||
#: code:addons/report_qweb_parameter/models/ir_qweb.py:16 | ||
#, python-format | ||
msgid "Length cannot be less than %s" | ||
msgstr "" | ||
|
||
#. module: report_qweb_parameter | ||
#: code:addons/report_qweb_parameter/models/ir_qweb.py:19 | ||
#, python-format | ||
msgid "Length cannot be more than %s" | ||
msgstr "" | ||
|
||
#. module: report_qweb_parameter | ||
#: model:ir.model,name:report_qweb_parameter.model_ir_qweb | ||
msgid "ir.qweb" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import ir_qweb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- 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.exceptions import ValidationError | ||
|
||
|
||
class IrQWeb(models.AbstractModel): | ||
_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)) | ||
if max_length and len(value) > 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) | ||
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 + ']' | ||
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) | ||
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 + ']' | ||
return super(IrQWeb, self)._compile_directive_raw(el, options) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_report_qweb_parameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- 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 | ||
|
||
|
||
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) | ||
|
||
docs = self.env['res.company'].search([], limit=1) | ||
vat = docs.vat | ||
website = docs.website | ||
street = docs.street | ||
company_registry = docs.company_registry | ||
docs.update({ | ||
'street': '12345678901', | ||
'vat': '12345678901', | ||
'website': '1234567890', | ||
'company_registry': '1234567890' | ||
}) | ||
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'}) | ||
with self.assertRaises(QWebException): | ||
report_object.render(docs.ids, False) | ||
docs.update({'street': '1234567890', 'vat': '123456789'}) | ||
with self.assertRaises(QWebException): | ||
report_object.render(docs.ids, False) | ||
docs.update({'vat': '1234567890', 'website': '12345678901'}) | ||
with self.assertRaises(QWebException): | ||
report_object.render(docs.ids, False) | ||
docs.update( | ||
{'website': '1234567890', 'company_registry': '12345678901'}) | ||
with self.assertRaises(QWebException): | ||
report_object.render(docs.ids, False) | ||
docs.update({ | ||
'street': street, | ||
'vat': vat, | ||
'website': website, | ||
'company_registry': company_registry | ||
}) |