Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions report_qweb_parameter/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ Authors
Contributors
------------

- Enric Tobella <etobella@creublanca.es>
- Enric Tobella <etobella@creublanca.es>

- `Tecnativa <https://www.tecnativa.com>`__:
- `Tecnativa <https://www.tecnativa.com>`__:

- Carlos Roca
- Carlos Roca

- Iván Antón <ozono@ozonomultimedia.com>
- Iván Antón <ozono@ozonomultimedia.com>

- `Sygel Technology <https://www.sygel.es>`__:

- Valentin Vinagre

Maintainers
-----------
Expand Down
19 changes: 17 additions & 2 deletions report_qweb_parameter/demo/test_report_field_length.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,21 +33,31 @@
t-out="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"
t-out="docs[0].company_registry"
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"
Expand Down
4 changes: 2 additions & 2 deletions report_qweb_parameter/models/ir_qweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _compile_directive_out(self, el, compile_context, level):
)
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):
Expand All @@ -68,5 +68,5 @@ def _compile_directive_raw(self, el, compile_context, level):
)
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)
4 changes: 4 additions & 0 deletions report_qweb_parameter/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
> - Carlos Roca

- Iván Antón \<<ozono@ozonomultimedia.com>\>

- [Sygel Technology](https://www.sygel.es):

> - Valentin Vinagre
7 changes: 7 additions & 0 deletions report_qweb_parameter/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</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">
Expand Down
13 changes: 11 additions & 2 deletions report_qweb_parameter/tests/test_report_qweb_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ def test_qweb_parameter(self):
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)
Expand Down
Loading