2016-03-04 57 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

沒問題,但最後歡迎和不錯的努力來解決你的自我 –