如何在openerp 7 webkit报告中修复此错误“TypeError:'未定义'对象不可调用”?

时间:2013-05-30 00:39:52

标签: openerp mako

我用webkit报告中的amount_to_text函数尝试了我所知道的一切,但我只是无处可去。我查看了支票编写模块,并尽可能多地复制它,但仍然没有结果。我使用的是webkit而不是rml,我不确定这是否会对v7产生影响,因为相同的代码在6.1中工作正常。任何帮助都将非常感激

这是.py文件中的代码:

import time
from report import report_sxw
from osv import osv     
from openerp.osv import osv,fields
from openerp.tools.translate import _
from openerp.tools.amount_to_text_en import amount_to_text

class tax_receipt(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(tax_receipt, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
            'cr':cr,
            'uid': uid,
            'amount_to_text': amount_to_text,
        })

report_sxw.report_sxw('report.tax.receipt',
                       'account.bank.statement.line', 
                       'addons/account_financial_report_webkit/report/webkit_html_bank_statement.mako',
                       parser=tax_receipt)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

mako文件的摘录如下所示:

<table width="95%" cellpadding="5px" cellpadding="5px">
    <tbody>
      <tr style="text-align:left;border-bottom:1px solid;">
        <td width="10%">The sum of </td>
        <td width="80%" style="text-align:left;border-bottom:1px solid;">**${ amount_to_text(inv.amount) }**</td>
      </tr> 
    </tbody>
</table>

当我尝试生成报告时,我得到:

Traceback (most recent call last):
File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\report_webkit\webkit_report.py", line 266, in create_single_pdf

File "mako\template.pyc", line 302, in render

File "mako\runtime.pyc", line 660, in _render

File "mako\runtime.pyc", line 692, in _render_context

File "mako\runtime.pyc", line 718, in _exec_template

File "memory:0x4a2d6d0", line 78, in render_body
<td width="80%" style="text-align:left;border-bottom:1px solid;">${ amount_to_text(inv.amount) }</td>
TypeError: 'Undefined' object is not callable

谢谢。

2 个答案:

答案 0 :(得分:1)

确保您的.py解析器已在您的模块中正确导入,即 init .py

### __init__.py file###

import your_parser

答案 1 :(得分:1)

我不确定你在哪里有使用amount_to_text函数的函数defenition。在openerp 7中,必须以这种方式指定。

class tax_receipt(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(tax_receipt, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
            'cr':cr,
            'uid': uid,
            'amount_to_text': self._amount_to_text,
        })
def _amount_to_text(self):
        res_users_obj = pooler.get_pool(self.cr.dbname).get('res.users')
        company_vat = res_users_obj.browse(self.cr, self.uid, self.uid).company_id.partner_id.vat
        return company_vat

在报告中,您已使用此

<table width="95%" cellpadding="5px" cellpadding="5px">
    <tbody>
      <tr style="text-align:left;border-bottom:1px solid;">
        <td width="10%">The sum of </td>
        <td width="80%" style="text-align:left;border-bottom:1px solid;">${amount_to_text(inv.amount)} </td>
      </tr> 
    </tbody>
</table>

存储在您使用

的变量中
<% res_text = amount_to_text(inv.amount) %>

并打印

${res_text}

查看sale_order_webkit模块以获取示例。并回复澄清。祝你好运!!