Odoo V8自定义发票报告报错:External ID未在系统中找到
解决Odoo V8自定义发票报告模板不被识别的问题
看了你的代码,我发现几个关键问题导致系统无法正确解析你的模板,下面逐一说明并给出修正方案:
1. 致命的循环引用问题
你的模板里用了 <t t-call="clusterbrands_custom_report_invoice">,这意味着你在调用模板自身,会触发无限循环,Odoo根本无法处理这种结构。如果是基于Odoo默认发票报告做自定义,应该调用官方的基础模板,比如 account.report_invoice。
2. 语法错误(未闭合的属性)
在总计行的代码里,t-field-options 被截断了,原代码的这部分明显不完整,会直接导致模板解析失败,需要补全货币组件的配置。
3. 模板结构规范问题
如果是扩展默认报告,建议通过 inherit_id 继承官方模板;如果是完全自定义,也要确保整体结构符合Odoo QWeb的语法规范。
修正后的完整代码
<?xml version="1.0" encoding="utf-8"?> <openerp> <data> <!-- 继承默认发票报告模板,若为全新模板可移除inherit_id --> <template id="clusterbrands_custom_report_invoice" inherit_id="account.report_invoice"> <!-- 调用官方基础模板,避免循环引用 --> <t t-call="account.report_invoice"> <div class="page"> <div class="spacer" style="margin-top: 40px;"></div> <div class="row space-bottom"> <div class="col-xs-2"> <h3> <b>Razon social: </b> <span t-field="o.partner_id.name"/> <br/> <span t-if="o.partner_id.vat"> <b>R.I.F.: </b> </span> <span t-esc="o.partner_id.vat[2:]"/> <br/> <b>Telf:</b> <span t-field="o.partner_id.phone"/> </h3> </div> <div class="col-xs-3"> <h3> <b>Dirección Fiscal:</b> <br/> <span t-field="o.partner_id.street"/> <span t-field="o.partner_id.street2"/> <span t-field="o.partner_id.city"/> <span t-field="o.partner_id.state_id"/> </h3> </div> <div class="col-xs-4 text-center"> <h4> <div t-if="o.name" class="col-xs-4"> <p><strong> Descripción: </strong></p> <span t-field="o.name"/> </div> <div t-if="o.origin" class="col-xs-4"> <strong> Doc. Origen: </strong> <br/> <span t-field="o.origin"/> </div> <div t-if="o.partner_id.ref" class="col-xs-4"> <strong> Codigo Cliente: </strong> <br/> <span t-field="o.partner_id.ref"/> </div> <div t-if="o.reference" class="col-xs-4"> <strong> Ref: </strong> <br/> <span t-field="o.reference"/> </div> <div t-if="o.user_id" class="col-xs-4"> <strong> Comercial: </strong> <br/> <span t-field="o.user_id" /> </div> </h4> </div> <div class="col-xs-3 text-right"> <h3> <strong> <span t-if="o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')">Factura</span> <span t-if="o.type == 'out_invoice' and o.state == 'proforma2'">PRO-FORMA</span> <span t-if="o.type == 'out_invoice' and o.state == 'draft'">Factura Borrador</span> <span t-if="o.type == 'out_invoice' and o.state == 'cancel'">Factura Cancelada</span> <span t-if="o.type == 'out_refund'">Reembolso</span> <span t-if="o.type == 'in_refund'">Reembolso Proveedor</span> <span t-if="o.type == 'in_invoice'">Factura Proveedor</span> <span t-field="o.nro_ctrl"/> </strong> <br/> <strong>Fecha emisión:</strong> <span t-field="o.date_document"/> <br/> <strong>Fecha vcto:</strong> <span t-field="o.date_due"/> </h3> </div> </div> <table class="table table-condensed"> <thead> <tr> <th>Código</th> <th>Descripción</th> <th>Cant</th> <th>Precio Unit.</th> <th class="text-center" groups="sale.group_discount_per_so_line">Descuento (%)</th> <th class="text-center">Sub total</th> </tr> </thead> <tbody class="invoice_tbody"> <tr t-foreach="o.invoice_line" t-as="l"> <td style="width: 10%"><span t-field="l.product_id.default_code"/></td> <td style="width: 40%"><span t-field="l.name"/></td> <td> <span t-field="l.quantity"/> <span t-field="l.uos_id" groups="product.group_uom"/> </td> <td> <span t-field="l.price_unit"/> </td> <td class="text-center" groups="sale.group_discount_per_so_line"><span t-field="l.discount"/></td> <td class="text-center"> <span t-field="l.price_subtotal" /> </td> </tr> </tbody> </table> <div class="row"> <div class="col-xs-3 pull-right"> <table class="table table-condensed"> <tr> <td><strong>Sub total</strong></td> <td class="text-right"> <span t-field="o.amount_untaxed" t-field-options="{'widget': 'monetary', 'display_currency': 'o.currency_id'}"/> </td> </tr> <tr> <td><strong>I.V.A. <span t-esc="o.tax_line.name[:3]"></span></strong></td> <td class="text-right"> <span t-field="o.amount_tax" t-field-options="{'widget': 'monetary', 'display_currency': 'o.currency_id'}"/> </td> </tr> <tr> <td><strong>Total</strong></td> <td class="text-right"> <span t-field="o.amount_total" t-field-options="{'widget': 'monetary', 'display_currency': 'o.currency_id'}"/> </td> </tr> </table> </div> </div> </div> </t> </template> </data> </openerp>
额外检查项
- 确保你的模块在
__openerp__.py的depends列表中添加了'account'依赖,否则无法调用官方发票模板。 - 如果是全新报告,需要在模块中创建
ir.actions.report.xml记录,将该模板关联到发票模型。 - 确认模板ID在整个Odoo环境中唯一,避免和其他模块的模板冲突。
内容的提问来源于stack exchange,提问作者alejandrohtadinom
相关产品推荐
相关产品推荐

