Skip to Content
Menu
This question has been flagged
3 Replies
20031 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

Avatar
Discard
Best Answer

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)
        self.localcontext.update({
            'time': time,
            'num2words':num2word,
            'get_contact_chield':self.get_contact_chield,
        })

and use in your view xml file as report file

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

 

Avatar
Discard
Best Answer

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)
        self.localcontext.update({
            'time': time, 
            'show_discount':self._show_discount,
            'amount_to_text': amount_to_text,
            'amount_to_text_en': amount_to_text_en
        })

Then in the corresponding rml file add

 [[str(amount_to_text(o.amount_total,"Ruppes"))]]

And Restart the server

Avatar
Discard
Author

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_change function shows output Rupees in word in the form. To show only in reports the above code updated

Author

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

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

Author

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..

Author Best Answer
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"),

             }  

sale_order()

In XML file..

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
  <data> 
    <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"/> 
          </field>
        <!-- </form>-->
       </field>
    </record>

<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>

</record>

</data> </openerp>

Avatar
Discard

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)"/

Author

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..

Author

thanks prakash.