【问题标题】:How do I fix this error "TypeError: 'Undefined' object is not callable" in openerp 7 webkit report?如何在 openerp 7 webkit 报告中修复此错误“TypeError: 'Undefined' object is not callable”?
【发布时间】:2013-05-25 10:29:53
【问题描述】:

我已经用 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

谢谢。

【问题讨论】:

    标签: openerp mako


    【解决方案1】:

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

    中
    ### __init__.py file###
    
    import your_parser
    

    【讨论】:

      【解决方案2】:

      我不确定你在哪里有 amount_to_text 函数的函数定义。在 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 模块以获取示例。并返回以进行澄清。祝你好运!!

      【讨论】:

        猜你喜欢
        • 2013-05-28
        • 1970-01-01
        • 1970-01-01
        • 2018-01-26
        • 1970-01-01
        • 2016-03-25
        • 2016-04-25
        • 2021-09-15
        • 1970-01-01
        相关资源
        最近更新 更多