Incorrect amount_to_text_en.py

Bug #522192 reported by Ivan Gudym
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Wishlist
OpenERP's Framework R&D

Bug Description

amount_to_text_en.py incorrect in structure. It shouldn't redefine so called "generic" functions and variables from amount_to_text.py, but should extend it in proper way - by using add_amount_to_text_function function.
To avoid confusion i propose to leave in amount_to_text.py "generic" functions only, and all localisation staff turn into amount_to_text_fr.py and so on.
Modules shouldn't direct use any "amount_to_text_XX" function, instead it should call generic amount_to_text.

Here is incorrect use from /account_voucher/report/report_voucher.py :

38 def convert(self,amount, cur):
39 amt_en = amount_to_text_en.amount_to_text(amount,'en',cur);
40 return amt_en

Revision history for this message
Ivan Gudym (igudym) wrote :
Revision history for this message
Ivan Gudym (igudym) wrote :
Revision history for this message
Ivan Gudym (igudym) wrote :
Revision history for this message
Ivan Gudym (igudym) wrote :
Revision history for this message
Ivan Gudym (igudym) wrote :

Usage in localisation module:

from amount_to_text_ua import amount_to_text_ua
from tools.amount_to_text import add_amount_to_text_function

add_amount_to_text_function('uk', amount_to_text_ua)

Using in localized report:

from tools.amount_to_text import amount_to_text

class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
            'convert': self.convert,
        })

    def convert(self,amount):
        return amount_to_text(amount, 'uk')

Changed in openobject-server:
assignee: nobody → DHS(OpenERP) (dhs-openerp)
Changed in openobject-server:
status: New → Confirmed
importance: Undecided → Wishlist
Changed in openobject-server:
assignee: DHS(OpenERP) (dhs-openerp) → OpenERP's Framework R&D (openerp-dev-framework)
Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote :
Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote :

In my opinion this should have been set up a base module, with the possibility of inheriting l10n localization modules for this purpose

Revision history for this message
xrg (xrg) wrote : Re: [Bug 522192] Re: Incorrect amount_to_text_en.py

On Saturday 14 May 2011, you wrote:
> In my opinion this should have been set up a base module, with the
> possibility of inheriting l10n localization modules for this purpose

Does this API look good for you:

http://git.hellug.gr/?p=xrg/openobject-
server;a=commitdiff;h=e6bee8c23828781c9c7

??

Revision history for this message
xrg (xrg) wrote :

On Saturday 14 May 2011, you wrote:
> ** Attachment added: "Amount to Text es_MX"
>
> https://bugs.launchpad.net/openobject-server/+bug/522192/+attachment/21277
> 96/+files/amount_to_text_es_mx.py

Cool, I think I can use this ;)

Revision history for this message
xrg (xrg) wrote :

On Saturday 14 May 2011, you wrote:
> ** Attachment added: "Amount to Text es_MX"
>
> https://bugs.launchpad.net/openobject-server/+bug/522192/+attachment/21277
> 96/+files/amount_to_text_es_mx.py

Hello.
I have read your patch..

Although I don't deny it does the job (of formulating a string for your
needs), I would ask you to clean it up a bit.

Please, add a few _english_ comments on what each function does. You need to
explain to a non-Spanish speaker why the code looks like this etc.
How does it apply to 'pesos', would it work for Euro or Dollars (wrt.
Feminine/Masculine genders), to hours or other UoMs (or quantities)?

Also, try to avoid in-line conditionals. Being a C old-timer, I can understand
this syntax. But in python they are not very welcome.
( I mean, the ones like
       if amount == 10 : res = "ten"
)

I would also recommend you to write a few tests, where the numerical quantity
passes through your function and is then compared with a fixed string. Like:
     assert amount2text("1500", "Eur") == 'One thousand five hundred Eur"

Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote :
Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote :

Hello XRG,
I attaching the code a little cleaner and with English translation of each function.
Note that this function is recursive, therefore, has no limits on amounts.
example 500,000,000,000
Returns: Quinientos mil millones

Saludos!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.