Odoo 10自定义Qweb报告:渲染编译AST TypeError时出错:'NoneType'对象不可调用

问题描述 投票:0回答:1

我正在尝试从供应商模块扩展现有报告,插入转换为文本的金额,因此我从头开始为报告创建模块:

这是我的report_file.py

from openerp import api, models
from num2words import num2words

class ReportReceiptReprint(models.AbstractModel):
    _name = 'report.aces_pos_reorder.receipt_reprint'

@api.multi
def _numwords(val):
    pretext = val
    text = ''
    entire_part = int((str(pretext).split('.'))[0])
    decimal_part = int((str(pretext).split('.'))[1])  
    text+=num2words(entire_part, lang='es').upper()
    text+=' CON '
    text+=num2words(decimal_part, lang='es').upper()
    if decimal_num > 1:
        text+= ' CENTAVOS '
    else:
        text+= ' CENTAVO '
    return text

@api.multi
def render_html(self, docids, data=None):
    report = self.env['report']._get_report_from_name('aces_pos_reorder.receipt_reprint')
    docargs = {
        'doc_ids': docids,
        'doc_model': report.model,
        'docs': self,
        'num_words': _numwords,
        }
    return self.env['report'].render('aces_pos_reorder.receipt_reprint', docargs)

还有我的report_file.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
   <template id="report_receipt_reprint_inherit" inherit_id="aces_pos_reorder.receipt_reprint">
     <xpath expr="//div[@class='numbers_text']" position="replace">
        <div style="font-size: 14px; width: 100%">
          <b>Son: <span t-esc="num_words(receipt.amount_total)"/></b>
        </div>
     </xpath>
   </template>
</data>
</odoo>

但是我刚得到这个:

Error to render compiling AST
TypeError: 'NoneType' object is not callable
Template: 1130
Path: /templates/t/t/div[2]/div[9]/div[1]/b/span
Node: <span t-esc="num_words(receipt.amount_total)"/>

即使将函数_numwords()放入主模块的models.py文件中,也会发生这种情况。如果我避免调用该函数,则模块的扩展将起作用,将按预期插入文本。已安装num2words。

我将不胜感激任何意见或建议!预先感谢。

report odoo-10 qweb
1个回答
0
投票
在您的python文件上,只需将函数调用更改为,

'num_words':self._numwords(data ['form'] ['amount_total']),&def _numwords(self,val)

请确保检查您传递的

amount_total

值是否来自数据,并且必须将该值传递给_numwords函数。然后在XML文件t-esc =“ num_words”上尝试访问这样的值。谢谢
© www.soinside.com 2019 - 2024. All rights reserved.