2014-02-18 107 views
0

我的報告文件中包含無法調用Python函數中的Webkit報告的OpenERP

class AccountInvoice_Report(report_sxw.rml_parse): 

    def __init__(self, cr, uid, name, context): 

     super(AccountInvoice_Report, self).__init__(cr, uid, name, context=context) 

     self.localcontext.update({ 

     'time': time, 
     'cr':cr, 
     'uid': uid, 
     'get_address': self.get_address, 
    }) 

,我已經寫get_address功能。當我調用該函數在我的真子文件

<% get_address() %> 

然後它給了錯誤的

File "memory:0xb23c67ccL", line 208, in render_body 
    <% get_address()%> 
    TypeError: 'Undefined' object is not callable 

我在做什麼文件錯誤定義或調用函數。

回答

0

my_parser.py

import time 
from openerp.report import report_sxw 

class AccountInvoice_Report(report_sxw.rml_parse): 

    def __init__(self, cr, uid, name, context): 
     super(AccountInvoice_Report, self).__init__(cr, uid, name, context=context) 
     self.localcontext.update({ 
            'time': time, 
            'cr':cr, 
            'uid': uid, 
            'get_address': self.get_address,}) 
    def get_address(self): 
     #your code 
     return 'address' 

report_sxw.report_sxw('report.your_report_name', 'model', 'path/to/mako', parser=AccountInvoice_Report) 

包括此解析器__init__.py

import my_parser 

也不要忘了導入您的報告文件夾中的主要__init__.py

+0

這是基本的東西。我已包括它。如果我沒有,那麼錯誤將會不同。請檢查錯誤。 –

+1

如果你不導入文件夾,錯誤將會是相同的。我之前面臨同樣的問題,因爲我忘記了包含它。你有沒有檢查你的自定義分析器是否被調用,放置斷點並檢查。 – sajadkk

+0

能否詳細說明自定義解析器檢查.. –

0

也可以嘗試重新啓動IDE /服務器。這個對我有用。有時你可以同時運行多個實例。

0

在:

report_sxw.report_sxw('report.your_report_name', 'model', 'path/to/mako', parser=AccountInvoice_Report) 

你應該確保你的 'your_report_name' 是相同的型號 'ir.actions.report.xml'(其中您配置報告)領域的 'REPORT_NAME'。

函數report_sxw.report_sxw()找不到報告的'report_name'來鏈接解析器。

0

這是一個古老的問題,但也許有人可以利用這一點。我用你正在試圖做的方法,下面的代碼爲我工作在6.0: 在您初始化,而不是

'get_address': self.get_address,})

我用:

'get_address': self.get_address(),})

然後我宣佈我的方法爲:

def get_address(self):

${get_address}

注意,上灰鯖文件我沒有使用「get_address()」,因爲它給我發了一個錯誤,指出該字符串get_address不是:

最後在我的灰鯖我把它稱爲可調用對象。希望能幫助到你。