I'm trying to extended an existing report from a vendor module, inserting the amount converted to text, so I started from scratch creating the module for my report:
This is my 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)
And my 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>
but I just get this:
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)"/>
This happen even if I put the function _numwords() into the models.py file of the main module. The extend for the module works if I avoid to call the function, the text is inserted as expected. num2words is installed.
I'll appreciate any comment or suggestion! Thanks in advance.
==EDIT==
report_file.py
from odoo import api, models
from num2words import num2words
class ReportReceiptReprint(models.AbstractModel):
_name = 'report.aces_pos_reorder.receipt_reprint'
@api.multi
def _numwords(self, val):
pretext = float(val)
text = ''
entire_part = int((str(pretext).split('.'))[0])
decimal_part = (pretext-float(entire_part))*100
decimal_part = int((str(decimal_part).split('.'))[0])
text += num2words(entire_part, lang='es').upper()
text += ' LEMPIRAS CON '
text += num2words(decimal_part, lang='es').upper()
if decimal_part > 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': self.env.context.get('active_model'),
'docs': self.env['pos.order'].browse(int(docids)),
'num_words': self._numbwords,
}
return self.env['report'].render('aces_pos_reorder.receipt_reprint', docargs)
I don't know why the commented line "# report =" was causing a lot of problems.