Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Getting error: TemplateAssertionError: no filter named 'n' when printing report?

By
Yakito
on 2/5/15, 8:05 PM 1,308 views

I am trying to print a report for a custom module I am building with Odoo, but when I try to print I get the following error:

File "/opt/odoo/openerp/service/report.py", line 93, in go result, format = openerp.report.render_report(cr, uid, ids, object, datas, context) File "/opt/odoo/openerp/report/__init__.py", line 40, in render_report return registry['ir.actions.report.xml'].render_report(cr, uid, ids, name, data, context) File "/opt/odoo/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/opt/odoo/openerp/addons/base/ir/ir_actions.py", line 155, in render_report return new_report.create(cr, uid, res_ids, data, context) File "/opt/odoo/addons/report_webkit/webkit_report.py", line 376, in create result = self.create_source_pdf(cursor, uid, ids, data, report_xml, context) File "/opt/odoo/openerp/report/report_sxw.py", line 461, in create_source_pdf return self.create_single_pdf(cr, uid, ids, data, report_xml, context) File "/opt/odoo/addons/report_webkit/webkit_report.py", line 334, in create_single_pdf head_mako_tpl = mako_template(header) File "/opt/odoo/addons/report_webkit/webkit_report.py", line 88, in mako_template return mako_template_env.from_string(text) File "/usr/local/lib/python2.7/dist-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 769, in from_string return cls.from_code(self, self.compile(source), globals, None) File "/usr/local/lib/python2.7/dist-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 493, in compile self.handle_exception(exc_info, source_hint=source) File "<unknown>", line 24, in template TemplateAssertionError: no filter named 'n'

I googled a lot and couldn't find any clue as to how to solve that issue.

I am using webkit reporting. Here is my .mako file.

<html> <head> <style type="text/css"> </style> </head> <body> Testing </body> </html>

This is how I call the report from the .py file

report_sxw.report_sxw('report.hotel.webkit', 'hotel.webkit', 'addons/hotel_webkit/report/report_hotel.mako', parser=report_webkit_html)

And finally the XML call

<report id="sim.report_sim_hotel" name="hotel.webkit" auto="False" model="sim.resumen_wizard" file="hotel_webkit/report/report_hotel.mako" string="Hotel Report Test" webkit_header="base_headers_webkit.base_reports_portrait_header" report_type="webkit"/>

Any clue as to what does that error means and what else can I test to make the report work will be appreciated.

Thanks

0
Danny W. Adair
On 6/22/15, 12:53 AM

I just fixed this issue for our invoices.

Odoo switched from Mako in v7 to Jinja2 in v8, with a "simulated" Mako notation where _most_ things work as before. Inline Python code doesn't, this "n" filter doesn't.

You have to switch from Mako's "|n" to Jinja2's "|safe" (this filter means "don't escape" - usually applied to things that return HTML).

  • http://docs.makotemplates.org/en/latest/filtering.html

  • http://jinja.pocoo.org/docs/dev/templates/#working-with-automatic-escaping

If you are not using it in your template, it is probably in your base header!

We had a line

${_debug or ''|n}

in there which should read

${_debug or ''|safe}

for Odoo.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/5/15, 8:05 PM
Seen: 1308 times
Last updated: 6/22/15, 12:53 AM