我正在尝试使用报表解析器,但它总是会弹出错误
ValueError The _name attribute report.test_module.report_test_doc is not valid
我搜索了你的报告名称用于解析器_template和_name,以供Odoo使用。如果我删除了test_module,它不会显示错误,但是hello()不可调用。
report.xml将
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="eport_monthly_pdc"
string="Monthly report of PDC"
model="account.voucher"
report_type="qweb-pdf"
name="test_module.report_test_doc"
file="test_module.report_test_doc"
/>
</data>
</openerp>
report_parser.朋友
from openerp import api, models
from openerp.report import report_sxw
import time
class report_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(report_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'hello_world': self._hello,
})
def _hello(self):
return "Hello World!"
class report_parser_test(models.AbstractModel):
_name = 'report.test_module.report_test_doc'
_inherit = 'report.abstract_report'
_template = 'test_module.report_test_doc'
_wrapped_report_class = report_parser
report_test_doc.xml
<openerp>
<data>
<template id="report_test_doc">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="test_module.report_test_layout">
<div class="page">
<div class="text-center">
<span t-esc="hello_world()"/>
</div>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>
在你的情况基本上,
Qweb报告主要用于使用每个报告类型的每个类条目的models.AbstractModel
模型进行调用,并在您的类中继承它以用于解析器类条目。
class report_parser_test(models.AbstractModel):
_name = 'report.test_module.report_test_doc'
_inherit = 'report.abstract_report'
_template = 'test_module.report_test_doc'
_wrapped_report_class = report_parser
每个Qweb报告解析器类的属性条目:
_name属性始终以report.<your report template id>
开头
_inherit ='report.abstract_report'它是report.abstract_report的默认继承,它位于报告模块中(每个报告的基类)
_template ='test_module.report_test_doc'
这基本上是<your module name>.<your report template id>
_wrapped_report_class = report_parser
这是您的解析器类的一部分,它包含您的报告的报告逻辑和计算逻辑。
**以及调用hello()调用的另一件事:
在你的情况下你的函数是声明并添加你的报告解析器类是好的但我们必须在Qweb模板文件上调用该函数
喜欢..
<span t-esc="hello()"/>
然后你将从你的结尾调用该函数。
我希望我的回答可能对你有所帮助:)
UPPERCASE中的模块名称(即目录)在Odoo11中引发此错误。例:
_name = 'report.Name_Module.report_name'