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.

0

Total amount in words

By
TJ
on 6/29/15, 2:25 AM 1,454 views

On the invoice I need the total amount in words (i.e. 10 EURO and 50 Cents).

Currently I use the onchange method on the amount_total field. This does converts it into words but is only called once because amount_total is a so-called functional field. This always results in Zero EURO and Zero Cents.

 def onchange_amount(self, cr, uid, ids, amount):
    x_text_amount = amount_to_text_en.amount_to_text(amount, 'en', 'EURO')
    return {'value': {'x_text_amount': x_text_amount}}

In account_invoice.py I need to change an existing function to update my new field amount_in_words. I thought I could update this field when the user validates an invoice. However I did not get this working.

I created the following to function already.

def _compute_amount_letter(self):
    self.x_amount_letter=self._get_amount_letter(self.amount_total)

def _get_amount_letter(self,amount):
    return amount_to_text_en(amount) 

Could you please help me how to change/update account_invoice.py - so that my field amount_in_words will be updated when the user validates the invoice / the total amount changes.

Many thanks!


Did you try by @api.onchange?

Serpent Consulting Services Pvt. Ltd.
on 6/29/15, 2:37 AM

Yes. I tried this: @api.depends('amount_total') def test(self): self.x_amount_letter = amount_to_text_en.amount_to_text(self.amount_total, 'en', 'EURO') But it is not triggered yet. Does not update the x_amount_total field. @Bole Yeah I only need it in the printed report.

TJ
on 6/29/15, 5:25 AM

I used @api.onchange. In the comment above I copied the wrong code.

TJ
on 6/29/15, 5:34 AM

Well if you only need that text in printed report, then you have no need for such field in database... simply call _compute_ammount_letter from report parser...

Bole
on 6/29/15, 5:44 AM
1

zbik

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


zbik
On 6/29/15, 2:29 PM

In report, I use:

<span t-if="o.currency_id" t-esc="o.currency_text(o.amount_total, o.currency_id.name, o.partner_id.lang or 'pl_PL')"/> 

where method currency_text() is defined in account_invoice as:

    @api.multi
def currency_text(self, sum, currency, language):
return currency_to_text(sum, currency, language)



3
Bailey
On 7/16/15, 8:26 AM

Hi

         Please see this link...https://www.odoo.com/es_ES/forum/help-1/question/functional-fields-in-openerp-convert-amount-to-word-string-24366


0
Bruno JOLIVEAU
On 7/22/15, 10:30 AM

Maybe you can have a look here

https://github.com/OCA/l10n-canada/tree/8.0/l10n_ca_account_check_writing

0
TJ
On 6/30/15, 6:26 AM
0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 6/29/15, 4:36 AM

Well ammount_to_text is usualy used in printed reports, 
but if you realy need that displayed maybe function field would do the trick... 
(that way you can have text value displayed whenever the ammount changes... )

0
Juan José Scarafía
On 6/29/15, 1:26 PM

Hi Tjardo,

I use what you say in printed reports, in receipt. The code is this one:

<number_to_string(o.total_amount)>

Regards,

Juan Jośe - ADHOC

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: 6/29/15, 2:25 AM
Seen: 1454 times
Last updated: 7/22/15, 10:30 AM