1

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

谢谢你。

4

2 回答 2

1

我不确定你在哪里有 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-09-03T10:45:53.703 回答
1

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

### __init__.py file###

import your_parser
于 2013-09-03T06:32:26.517 回答