我正在尝试创建QWeb报告。我有一个产品清单,我想在同一页上打印每个礼仪。这是我的代码:
<?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>
问题:当我选择要打印的所有产品时,我有一个错误(见下文)。但是当我只选择一种产品时,我可以打印报告。
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
有什么想法吗?
答案 0 :(得分:9)
问题与报表引擎期望每页有1个页眉和页脚的事实有关。您正在为1个页眉+页脚创建N页。
调用<t t-call="report.external_layout">
必须放在for循环中。如果您在同一页面中需要多个项目,请不要使用page
类作为包装器,因为这是引擎用于获取报告页面的内容。您可以查看source code。