2016-03-04 63 views
0

我试图用报告解析器,但它总是弹出一个错误0 ValueError _name属性report.test_module.report_test_doc无效。 [Qweb- Odoo]

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.py

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> 

回答

2

在你的情况基本上

Qweb报告主要是用来使用你的每一个类条目每个报告类型的models.AbstractModel模型来调用,并在你的类解析器类条目继承它。每个Qweb报告解析器类条目的

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 

属性:

_name属性它总是与report.<your report template id>

_inherit = 'report.abstract_report' 这是默认启动报告模块(每个R的基类)中的report.abstract_report的继承扩展端口)

_template = 'test_module.report_test_doc'

这基本上是<your module name>.<your report template id>

_wrapped_report_class = report_parser

你是哪个解析器类的项,这包含的一部分你为您的报告报告逻辑和计算逻辑。

**及有关打电话给你打招呼另一个东西()调用:

在你的情况你运行的情况下申报,并添加您的报告分析器类是好的,但我们必须需要调用Qweb模板函数文件

喜欢..

<span t-esc="hello()"/> 

然后,然后你会调用您的最终该功能。

我希望我的回答可能对你有所帮助:)

+0

我已经解决了这个问题,但upvoted! :) 谢谢。 – Fatima

+0

没问题,但最后欢迎和不错的努力来解决你的自我 –