Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWEB - IndexError: list index out of range

I'm trying to create a QWeb report. I have a list of product and I would like to print each etiquette on the same page. This is my code :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- Déclaration des rapports -->
            <report 
                id="etiquette_produit"
                model="product.template"
                string="Etiquette Produit"
                report_type="qweb-pdf"
                file="Product_Etiquette_QWeb.produit_etiquette"
                name="Product_Etiquette_QWeb.produit_etiquette"
            />

        <template id="produit_etiquette">
            <t t-call="report.external_layout">
                <t t-foreach="docs" t-as="o">
                    <div class="page">
                        <table class="table table-striped">
                            <tr>
                                <td class="col-xs-1"><span t-field="o.default_code"/></td>
                                <td class="col-xs-5 text-center"><span t-field="o.name"/></td>
                                <td class="col-xs-1"><span t-field="o.default_code"/></td>
                                <td class="col-xs-5 text-center"><span t-field="o.name"/></td>
                            </tr>
                            <tr>
                                <td colspan="2" class="text-center">* M E 2 1 5 9 *</td>
                                <td colspan="2" class="text-center">* M E 2 0 1 7 *</td>
                            </tr>
                        </table>
                    </div>
                </t>
            </t>
        </template>
    </data>
</openerp>

The problem : When I select all the products to print, i have an error (see below). But when i select only one product, i can print the report.

Odoo Server Error

Traceback (most recent call last):
  File "/opt/odoo/odoo-server/addons/report/controllers/main.py", line 116, in report_download
    response = self.report_routes(reportname, docids=docids, converter='pdf')
  File "/opt/odoo/odoo-server/openerp/http.py", line 405, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-server/addons/report/controllers/main.py", line 65, in report_routes
    pdf = report_obj.get_pdf(cr, uid, docids, reportname, data=options_data, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-server/addons/report/models/report.py", line 275, in get_pdf
    paperformat, specific_paperformat_args, save_in_attachment
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-server/addons/report/models/report.py", line 432, in _run_wkhtmltopdf
    head_file.write(headers[index])
IndexError: list index out of range

Any idea ?

like image 739
Gary Heldmann Avatar asked Dec 25 '22 05:12

Gary Heldmann


1 Answers

The issue is related to the fact that the report engine expects to have 1 header and footer for each page. You are creating N pages for 1 header+footer.

The call <t t-call="report.external_layout"> must be put inside the for loop. If you need more than one item in the same page do not use page class as wrapper, since that is what it used by the engine to fetch report pages. You can have a look at the source code.

like image 101
simahawk Avatar answered Dec 26 '22 19:12

simahawk