QWebException:“'NoneType'对象不可调用"在评估时 [英] QWebException: "'NoneType' object is not callable" while evaluating
问题描述
我在qweb报告中遇到问题,因此我遵循了本教程 http://blog .emiprotechnologies.com/create-qweb-report-odoo/来创建qweb报表,它可以与当前模块的静态数据一起很好地工作,但是当我尝试为动态数据创建解析器类时,我得到了错误"QWebException:'NoneType'对象不可调用",同时评估这是我的python类:
im facing a problem in qweb report, i followed this tutorial http://blog.emiprotechnologies.com/create-qweb-report-odoo/ to create qweb report, it worked fine with the static data of my current module, but when i try to create a parser class for dynamic data, i get this error " QWebException: "'NoneType' object is not callable" while evaluating " here it's my python class :
from openerp.osv import osv
from openerp.report import report_sxw
class etudiant_report_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(etudiant_report_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'hello_world': self.hello_world,
})
self.context = context
def hello_world(self):
return "hello"
class etudiant_object_report(osv.AbstractModel):
_name = 'report.gestion_des_etudiants.etudiant_report'
_inherit = 'report.abstract_report'
_template = 'gestion_des_etudiants.etudiant_report'
_wrapped_report_class = etudiant_report_parser
在我的xml文件etudiant_report.xml中,我添加了这一行:
And in my xml file etudiant_report.xml I added this line :
<span t-esc="hello_world()"/>
但是当我打印报告时,出现错误:
But when I print the report I get the error :
QWebException: "'NoneType' object is not callable" while evaluating
这是我的模块的树状结构:
Here it's the arborescence of my module :
/report/ init .py< ---加载包含解析器类的etudiant_report.xml
/report/init.py <--- to load the etudiant_report.xml which contains the parser class
/report/etudiant_report.py< --- ...包含解析器类
/report/etudiant_report.py <--- ...contains the parser class
/views/report_etudiant.xml< ---报告的xml文件
/views/report_etudiant.xml <--- the xml file for the report
初始化 .py
openerp .py
etudiant_view.xml
etudiant_view.xml
etudiant_report.xml< ---报告菜单
etudiant_report.xml <--- the menu of the report
etudiant.py
etudiant.py
我注意到的另一件事是,当我进入报告"文件夹时,找不到 init .py和etudiant_report.py
Another thing I noticed, when I go into the folder " report " I don't find any .pyc file, for init.py and etudiant_report.py
推荐答案
要从模型中调用自定义方法,可以执行以下操作.
In order to call a custom method from the model you can do followings.
定义模型中的方法
@api.multi
def mymethod(self):
return "mymethod"
然后从qweb调用该方法.这是qweb的示例代码,该代码从模型中调用自定义方法.
And then call the method from the qweb. here is the sample code of the qweb which is calling the custom method from the model.
<template id="th_custom_report">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="th_dynamic_report.th_report_id" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
<template id="th_report_id">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})" />
<span t-esc="o.mymethod()"/>
</t>
</t>
<template>
它将为您提供帮助!
这篇关于QWebException:“'NoneType'对象不可调用"在评估时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!