[FIX] report_qweb_parameter: out and raw doesn't work with conditionals

This commit is contained in:
valen
2025-01-15 12:35:41 +01:00
parent 2a388f6fa5
commit f47459b7c5
6 changed files with 52 additions and 11 deletions

View File

@@ -77,6 +77,10 @@ Contributors
* Iván Antón <ozono@ozonomultimedia.com>
* `Sygel Technology <https://www.sygel.es>`_:
* Valentin Vinagre
Maintainers
~~~~~~~~~~~

View File

@@ -15,6 +15,11 @@
t-esc="docs[0].street"
t-if="docs[0].street"
/>
<li
name="esc_conditional_length"
t-length="3"
t-esc="docs[0].name or docs[0].company_registry"
/>
<li
name="esc_maxlength"
t-maxlength="10"
@@ -28,6 +33,11 @@
t-raw="docs[0].vat"
t-if="docs[0].vat"
/>
<li
name="raw_conditional_length"
t-length="4"
t-raw="docs[0].name or docs[0].company_registry"
/>
<li
name="raw_maxlength"
t-maxlength="10"
@@ -35,14 +45,19 @@
t-if="docs[0].company_registry"
/>
<li
name="raw_length"
name="out_length"
t-minlength="10"
t-length="10"
t-out="docs[0].vat"
t-if="docs[0].vat"
/>
<li
name="raw_maxlength"
name="out_conditional_length"
t-length="5"
t-out="docs[0].name or docs[0].company_registry"
/>
<li
name="out_maxlength"
t-maxlength="10"
t-out="docs[0].company_registry"
t-if="docs[0].company_registry"

View File

@@ -49,7 +49,7 @@ class IrQWeb(models.AbstractModel):
)
if "t-length" in el.attrib:
tlength = el.attrib.pop("t-length")
el.attrib["t-out"] = el.attrib["t-out"] + "[:" + tlength + "]"
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):
@@ -68,5 +68,5 @@ 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 + "]"
el.attrib["t-raw"] = "(" + el.attrib["t-raw"] + ")[:" + tlength + "]"
return super()._compile_directive_raw(el, compile_context, level)

View File

@@ -5,3 +5,7 @@
* Carlos Roca
* Iván Antón <ozono@ozonomultimedia.com>
* `Sygel Technology <https://www.sygel.es>`_:
* Valentin Vinagre

View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
@@ -9,10 +8,11 @@
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -275,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@ span.option {
span.pre {
white-space: pre }
span.problematic {
span.problematic, pre.problematic {
color: red }
span.section-subtitle {
@@ -428,12 +428,21 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
</li>
<li><p class="first">Iván Antón &lt;<a class="reference external" href="mailto:ozono&#64;ozonomultimedia.com">ozono&#64;ozonomultimedia.com</a>&gt;</p>
</li>
<li><p class="first"><a class="reference external" href="https://www.sygel.es">Sygel Technology</a>:</p>
<blockquote>
<ul class="simple">
<li>Valentin Vinagre</li>
</ul>
</blockquote>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>

View File

@@ -24,9 +24,18 @@ class TestReportQWebParameter(common.TransactionCase):
docs.website = "1234567890" # for avoding that Odoo adds http://
rep = report_object._render(report_name, docs.ids, False)
root = ET.fromstring(rep[0])
# test length
self.assertEqual(root[0].text, "1234567890")
self.assertEqual(root[2].text, "1234567890")
self.assertEqual(root[4].text, "1234567890")
self.assertEqual(root[3].text, "1234567890")
self.assertEqual(root[6].text, "1234567890")
# test condicional 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(QWebException):
report_object._render(report_name, docs.ids, False)