Odoo Help

Welcome!

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

2

How to Add Amount in Words / Text to Printed Invoice?

By
Budi Hartono
on 4/2/15, 12:32 PM 4,431 views

 I am a beginner in programming both python and Odoo. I need a amount to text function that will display amount total in text in the printed invoice. I tried to follow this QWeb report tutorial: https://www.youtube.com/watch?v=tCAUm3MWYzk

Somehow I could create a module that modify the printed pdf. But I really don't have idea on how to put amount in text in the invoice PDF. I have searched the Odoo forum, only to find these guidances that failed to make me understand since I'm a noob:

https://www.odoo.com/forum/help-1/question/detailed-procedure-to-do-the-number-to-text-conversion-10504

https://www.odoo.com/forum/help-1/question/conversion-of-amount-to-text-in-openerp-43765

Here is the file content that modify the original report_invoice.xml. How to call the amount_to_text function in this report_invoice.xml below with the amount_to_text function that already exists in odoo/openerp/tools/amount_to_text.py?

addons/amount_text/views/report_invoice.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="report_invoice_document_inherit" inherit_id="account.report_invoice_document">
            <xpath expr="//div[@class='page']/div[@class='row mt32 mb32']" position="replace">

<div class="row mt32 mb32">32 mb32']" position="replace">
                <div class="row mt32 mb32">
                  <div class="col-xs-2" t-if="o.name">
                      <strong>Keterangan:</strong>
                      <p t-field="o.name"/>
                  </div>
                  <div class="col-xs-2" t-if="o.date_invoice">
                      <strong>Tanggal Invoice:</strong>
                      <p t-field="o.date_invoice"/>
                  </div>
                  <div class="col-xs-2" t-if="o.origin">
                      <strong>Asal:</strong>
                      <p t-field="o.origin"/>
                  </div>
                  <div class="col-xs-2" t-if="o.partner_id.ref">
                      <strong>Kode Customer:</strong>
                      <p t-field="o.partner_id.ref"/>
                  </div>
                  <div class="col-xs-2" t-if="o.reference">
                      <strong>Referensi:</strong>
                      <p t-field="o.reference"/>
                  </div>
              </div>
            </xpath>
            <xpath expr="//table[@class='table table-condensed']" position="after">
            <p>
                <strong>Amount in Text:</strong>                
                <!-- <span t-esc="openerp.tools.amount_to_text(o.amount_total, 'usd')"/> -->
            </p>
            </xpath>
        </template>
    </data>
</openerp>

1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 4/2/15, 1:51 PM

You inherit class account_invoice() like this:

class account_invoice(models.Model):
    _inherit = "account.invoice"
   @api.multi
   def amount_to_text(self, amount, currency='Euro'):
       return amount_to_text(amount, currency)

call in xml

<span t-esc="o.amount_to_text(o.amount_total, 'Euro')"/> 


0
B.hind
On 6/23/16, 10:07 AM

hi ,

when i try this code , it isn't working , i have this error

i dont  know how to solve it

File "/opt/odoo/addons/recu_facture/facture.py", line 23, in amount_to_text
    return amount_to_text(amount,currency)
QWebException: ""global name 'amount_to_text' is not defined" while evaluating
"o.amount_to_text(o.amount_total,'Euro')"" while evaluating
"translate_doc(doc_id, doc_model, 'partner_id.lang','recu_facture.recufacture_document')"
0
le_dilem
On 8/6/15, 10:21 AM

Hi,

https://github.com/ledilem/Odoo

Thanks, I'll take a look

Budi Hartono
on 8/8/15, 4:55 AM
0
Budi Hartono
On 4/3/15, 11:33 AM

Hi zbik,

Thanks a lot for your reply.

I did what you told, and I got this error.

QWebException: ""'account.invoice' object has no attribute 'amount_to_text'" while evaluating
"o.amount_to_text(o.amount_total, 'Euro')"" while evaluating
"translate_doc(doc_id, doc_model, 'partner_id.lang', 'account.report_invoice_document')"

FYI, these are the files in my modules:

amount_text folder:

views\report_invoice.xml
__init__.py
__openerp__.py
account_invoice.py
In the account_invoice.py

from openerp.tools import amount_to_text
class account_invoice(models.Model):
    _inherit = "account.invoice"
   @api.multi
   def amount_to_text(self, amount, currency='Euro'):
       return amount_to_text(amount, currency)

__init__.py

import account_invoice

__openerp__.py

{
   "name": "Amount Text",
    "version": "1.0.0",
    "depends": ["base"],
    "author": "Budi Hartono",
    "category": "",
    "description": """
    Amount to text.
    """,
    "website": "http://www.recoremedia.com",
    "depends": ["base"],
    "data": ["views/report_invoice.xml"],
    "installable": True,
    "active": False,
    #    "certificate": "",
}

views\report_invoice.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="report_invoice_document_inherit" inherit_id="account.report_invoice_document">
            <xpath expr="//div[@class='page']/div[@class='row mt32 mb32']" position="replace">
                <div class="row mt32 mb32">
                  <div class="col-xs-2" t-if="o.name">
                      <strong>Keterangan:</strong>
                      <p t-field="o.name"/>
                  </div>
                  <div class="col-xs-2" t-if="o.date_invoice">
                      <strong>Tanggal Invoice:</strong>
                      <p t-field="o.date_invoice"/>
                  </div>
                  <div class="col-xs-2" t-if="o.origin">
                      <strong>Asal:</strong>
                      <p t-field="o.origin"/>
                  </div>
                  <div class="col-xs-2" t-if="o.partner_id.ref">
                      <strong>Kode Customer:</strong>
                      <p t-field="o.partner_id.ref"/>
                  </div>
                  <div class="col-xs-2" t-if="o.reference">
                      <strong>Referensi:</strong>
                      <p t-field="o.reference"/>
                  </div>
              </div>
            </xpath>
            <xpath expr="//table[@class='table table-condensed']" position="after">
            <p>
                <strong>Amount in Text:</strong>                
                <span t-esc="o.amount_to_text(o.amount_total, 'Euro')"/> 
            </p>
            </xpath>
        </template>
    </data>
</openerp>

Try it: "depends": ["account", "report"]

zbik
on 4/3/15, 1:33 PM

... in __openerp__.py and ... update your module.

zbik
on 4/3/15, 1:35 PM

Hi zbik, Thanks, now it's working. You saved my live :) Anyway, I still have to add some import directives in the account_invoice.py to avoid further error messages: from openerp import api from openerp import models, fields

Budi Hartono
on 4/4/15, 12:49 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 4/2/15, 12:32 PM
Seen: 4431 times
Last updated: 6/23/16, 10:07 AM