gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:31:26 28 4
gpt4 key购买 nike

我正在尝试在 Odoo 12 下创建自定义报告,以将其添加到订单 View 下的打印选项中。到目前为止一切顺利,我将 XML 包含在 list 中并在 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内部是什么,所以我可以完全理解它

提前致谢何塞

最佳答案

您正在尝试继承默认的 Odoo Sale Report,但您的report action调用是不同的。在您定制的报告中,对象没有分离 ['sale.order'] 因此,您没有得到任何对象,而不是对象。

只需浏览如何使用报表继承的链接 Sale-inheriting-and-modifying-qweb-reports/ .

XML File 上进行销售报告定制,

<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 文件

谢谢

关于自定义报告中的 Odoo 12 非类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60939159/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com