aeroo_reports icon indicating copy to clipboard operation
aeroo_reports copied to clipboard

Error when non-unicode char un "name" field of ir.actions.report.xml with parser

Open alexis-via opened this issue 9 years ago • 0 comments

If you define in an XML file an aeroo report with a "name" field that has a non-ASCII character, you will get this error message in the logs when you install the module:

report_aeroo: Error loading report parser: 'ascii' codec can't encode character u'\xe7' in position 33: ordinal not in range(128)

Example of a file report.xml that fails:

<record id="pos_receipt_invoice_style" model="ir.actions.report.xml">
    <field name="name">Reçu style facture</field>
    <field name="model">pos.order</field>
    <field name="report_name">pos.order.invoice.style</field>
    <field name="report_type">aeroo</field>
    <field name="in_format">oo-odt</field>
    <field name="report_rml">bug_encoding/report/receipt_invoice_style.odt</field>
    <field name="parser_state">loc</field>
    <field name="parser_loc">bug_encoding/report/receipt_invoice_style.py</field>
    <field name="tml_source">file</field>
    <field name="multi" eval="0"/>
    <field name="attachment_use" eval="0"/>
    <field name="out_format" ref="report_aeroo.report_mimetypes_pdf_odt"/>
    <field name="fallback_false" eval="0"/>
    <field name="styles_mode">default</field>
</record>

Code analysis: The crash happens in report_aeroo/report_xml.py line 124 on:

py_mod = imp.load_source(mod_name, filepath)

the variable mod_name contains "o8_test1_receipt_invoice_style_reçu_style_facture" that has a non-ascii char and it fails. This comes from the "key" variable, which is an argument of the method load_from_file(). This method is called from the create() method line 537 of report_xml.py:

parser=self.load_from_file(vals['parser_loc'], vals['name'].lower().replace(' ','_')) or parser

vals['name'] is the "name" field of the object ir.actions.report.xml, which may contains non-ascii characters.

It don't know what is the proper solution to solve this. Could we use vals['report_name'] ? Should we use unidecode() to remove the non-ascii chars ?

alexis-via avatar Apr 30 '15 22:04 alexis-via