自定义报告中的 Odoo 12 非类型错误

Odoo 12 NonType errors on custom report

我正在尝试在 Odoo 12 下创建自定义报告,以将其添加到订单视图下的打印选项中。到目前为止一切顺利,我在清单中包含了 XML 并在 sale_management/report 文件夹下创建了 XML。我在编辑时更新了模块,它编译正确。然而,一旦我按下打印按钮,我就会收到这个错误:

Error:
Odoo Server Error

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 347, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_829_149
  File "<template>", line 2, in body_call_content_148
AttributeError: 'NoneType' object has no attribute 'with_context'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1671, in report_download
    response = self.report_routes(reportname, docids=docids, converter=converter)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1612, in report_routes
    pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 712, in render_qweb_pdf
    html = self.with_context(context).render_qweb_html(res_ids, data=data)[0]
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 752, in render_qweb_html
    return self.render_template(self.report_name, data), 'html'
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 534, in render_template
    return view_obj.render_template(template, values)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1304, in render_template
    return self.browse(self.get_view_id(template)).render(values, engine)
  File "/usr/lib/python3/dist-packages/odoo/addons/web_editor/models/ir_ui_view.py", line 27, in render
    return super(IrUiView, self).render(values=values, engine=engine, minimal_qcontext=minimal_qcontext)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1313, in render
    return self.env[engine].render(self.id, qcontext)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_qweb.py", line 59, in render
    result = super(IrQWeb, self).render(id_or_xml_id, values=values, **context)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 275, in render
    self.compile(template, options)(self, body.append, values or {})
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 354, in _compiled_fn
    raise QWebException("Error to render compiling AST", e, path, node and etree.tostring(node[0], encoding='unicode'), name)
odoo.addons.base.models.qweb.QWebException: 'NoneType' object has no attribute 'with_context'
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 347, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_829_149
  File "<template>", line 2, in body_call_content_148
AttributeError: 'NoneType' object has no attribute 'with_context'

Error to render compiling AST
AttributeError: 'NoneType' object has no attribute 'with_context'
Template: 829
Path: /templates/t/t/t[1]
Node: <t t-set="doc" t-value="doc.with_context(lang=doc.partner_id.lang)"/>

出于测试目的,XML 几乎是已包含在名为 sale_report_templates.xml 的同一目录中的模板的逐字记录,我的整个文件是:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
        <report
            id="albaran_sin_valorar"
            string="Documento sin valorar"
            model="sale.order"
            report_type="qweb-pdf"
            name="sale_management.report_albaran_sin_valorar"
        />

<template id="report_albaran_sin_valorar" inherit_id="sale.report_saleorder_document">
    <xpath expr="//div[hasclass('page')]/p[@id='fiscal_position_remark']" position="after">
        <div t-if="doc.sale_order_option_ids and doc.state in ['draft', 'sent']">
            <t t-set="has_option_discount" t-value="any(doc.sale_order_option_ids.filtered(lambda o: o.discount$
            <h4>
                <span>Optional Products</span>
            </h4>
            <table class="table table-sm">
                <thead>
                    <tr>
                        <th class="text-left">Description</th>
                        <th t-if="has_option_discount" groups="sale.group_discount_per_so_line" class="text-lef$
                        <th class="text-right">Unit Price</th>
                    </tr>
                </thead>
                <tbody class="sale_tbody">
                    <tr t-foreach="doc.sale_order_option_ids" t-as="option">
                        <td>
                            <span t-field="option.name"/>
                        </td>
                        <td t-if="has_option_discount" groups="sale.group_discount_per_so_line">
   ...
   </template>
   </odoo>

我的问题是: ——当然有什么问题。 - 问题涉及的Odoo内部是什么,所以我可以完全理解它

提前致谢 何塞

您正在尝试 inheriting 默认 Odoo 销售报告 但您的 report action 呼叫不同。在您的自定义报告中,该对象未分离['sale.order'] 因此您得到的不是对象,而是none.

简单地浏览 link 如何使用报表继承 Sale-inheriting-and-modifying-qweb-reports/

XML 文件 用于销售报告定制,

<template id="report_saleorder_document_customise" inherit_id="sale.report_saleorder_document">
    <!-- Give the xpath according to your requirement -->
    <xpath expr="//table[hasclass('o_main_table')]//tr/th[@name='th_subtotal']" position="before">
       <!-- Add your customise with give the xpath -->
    </xpath>
</template>

__manifest__ 文件中添加 Xml 文件

谢谢