Odoo Help


Conversion of amount to text in openerp...

on 2/11/14, 12:49 AM 9,871 views

in order to convert the amount to text in the sales order

I add the following lines in the sale/report/sale_order.py

from openerp.tools import amount_to_text
from openerp.tools import amount_to_text_en

'amount_to_text_en': amount_to_text_en, In the code

Then in the corresponding rml file i add [[str(amount_to_text(o.amount_total,"Ruppes"))]]

And in report.sxw also added this line. [[str(amount_to_text(o.amount_total,"Ruppes"))]]

But it will not generate any change in the printable report..

By looking on the openerp-server log file below mentioned warning displayed..

openerp.tools.safe_eval: Cannot eval 'str(amount_to_text(o.amount_total,"Ruppes"))'

Traceback (most recent call last): File "/opt/openerp/server/openerp/tools/safe_eval.py", line 241, in safe_eval return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict) File "", line 1, in <module> NameError: name 'amount_to_text' is not defined

How can be make amount to text in openerp v7.0

On 2/12/14, 12:14 AM
from openerp.osv import fields, osv
from tools.translate import _
from openerp.tools import amount_to_text_en
from openerp.tools.amount_to_text_en import amount_to_text 

class sale_order(osv.osv):
  _inherit = 'sale.order'
  _description = "Sales Order"
  def _amount_in_words(self, cr, uid, ids, field_name, arg, context=None):
    cur_obj = self.pool.get('res.currency')
    res = {}
    for order in self.browse(cr, uid, ids, context=context):
        taxed = untaxed = 0.0
        res[order.id] = {
            'amount_words': '0.0',
        val = val1 = 0.0
        cur = order.pricelist_id.currency_id
        for line in order.order_line:
            val1 += line.price_subtotal
            val += self._amount_line_tax(cr, uid, line, context=context)
        taxed = cur_obj.round(cr, uid, cur, val)
        untaxed = cur_obj.round(cr, uid, cur, val1)
        res[order.id] = amount_to_text_en.amount_to_text(float(taxed + untaxed))
    return res

  _columns = {
              'amount_words': fields.function(_amount_in_words, string='In Words', type="char", store=True, help="The amount in words"),



In XML file..

<?xml version="1.0" encoding="UTF-8"?>
    <record model="ir.ui.view" id='view_report_order_form' >
      <field name="name">sale.order.form1</field>
      <field name="model">sale.order</field>
      <field name="inherit_id" ref="sale.view_order_form"/>
      <field name="arch" type="xml">
       <!-- <form string="Sales Order" version="7.0"> -->
          <field name="amount_total" position="after">
            <field name="amount_words"/> 
        <!-- </form>-->

<record model="ir.actions.act_window" id="action_orders">
<field name="name">Salereport1</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>


</data> </openerp>

In xml file onchange should be amount float change the code <field name="text_amount" on_change="onchange_amount_total(amount_total)"/> into <field name="amount_total" on_change="onchange_amount_total(amount_total)"/

on 2/12/14, 12:58 AM

hi prakash Issue partially solved . See the updated post above.. I commented the line <form string="Invoice" version="7.0"> and its closing tags. Now amount appears in Euro and Cent , is it possible to make it to indian format..

on 2/12/14, 2:16 AM

thanks prakash.

on 2/12/14, 3:12 AM



| 5 5 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 2/11/14, 1:51 AM

Add amount_to_text in init method also

For Example in the sale/report/sale_order.py

from openerp.tools import amount_to_text
from openerp.tools import amount_to_text_en

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(order, self).__init__(cr, uid, name, context=context)
            'time': time, 
            'amount_to_text': amount_to_text,
            'amount_to_text_en': amount_to_text_en

Then in the corresponding rml file add


And Restart the server

ok.. Gives words in report. Through inheritance I make new module by refering the this. http://help.openerp.com/question/10504/detailed-procedure-to-do-the-number-to-text-conversion/ Inheriting the sale order. Write onchange function for amount_total field ,but now updating the values . it appears to zero in total

on 2/11/14, 3:09 AM

on_change function shows output Rupees in word in the form. To show only in reports the above code updated

on 2/11/14, 3:25 AM

By using your code display in our report.. but in the salesorder form not display the words..

on 2/11/14, 4:17 AM

To display in the form follows the steps: http://help.openerp.com/question/10504/detailed-procedure-to-do-the-number-to-text-conversion/ 1) make sure to create field data type char or text 2) To define on_change method in xml file amount field 3) Restart the server and update the module 4) result will be generate after change the amount fields

on 2/11/14, 5:00 AM

hello prakash i will post my .py file and xml file. please check. During onchange my amount_total field became "Zero" . Will u please check the code and help me to find the solution..

on 2/12/14, 12:10 AM
Dasadiya Chaitanya
On 12/31/14, 4:02 AM

Another Way just need to install the num2word python library and use it in as your  .py file

from num2words import num2words

use it in Qweb report py file

    def __init__(self, cr, uid, name, context):
        super(supplair_invoice, self).__init__(cr, uid, name, context)
            'time': time,

and use in your view xml file as report file

<span t-esc="str(num2words(o.amount_total)).upper()"  />


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 2/11/14, 12:49 AM
Seen: 9871 times
Last updated: 3/16/15, 8:10 AM