0

我的报告文件包含

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 函数。当我在我的 mako 文件中调用该函数时

    <% get_address() %>

然后它给出错误为

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

我在做文件定义或调用函数时犯了什么错误。

4

4 回答 4

0

还尝试重新启动您的 IDE/服务器。这个对我有用。有时您可以同时运行多个实例。

于 2014-07-17T14:18:39.220 回答
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

也不要忘记在 main 中导入您的报告文件夹__init__.py

于 2014-02-20T15:46:52.853 回答
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”来链接解析器。

于 2015-05-06T08:23:55.753 回答
0

这是一个老问题,但也许有人可以利用它。我已经使用了您尝试执行的方法,并且以下代码在 6.0 上对我有用:在您的init上而不是

'get_address': self.get_address,})

我用了:

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

然后我将我的方法声明为:

def get_address(self):

最后在我的 mako 上,我用它来称呼它:

${get_address}

请注意,在 mako 文件中,我没有使用“get_address()”,因为它向我发送了一条错误消息,指出字符串 get_address 不是可调用对象。希望能帮助到你。

于 2018-02-09T15:26:22.160 回答