Saad Alhosan
Saad Alhosan

Reputation: 1

Cents are not Converted

converted the actual amount to word working fine but the cents are not converted, here's my .py code

def _get_amount_in_words(self, amount_total):

    # TODO: merge, refactor and complete the amount_to_text and amount_to_text_en classes

    amount_in_words = amount_to_text_en.amount_to_text(math.floor(amount_total), lang='en', currency='')

    amount_in_words = amount_in_words.replace(' and Zero Cent', '') # Ugh

    decimals = amount_total % 1

    if not float_is_zero(decimals, precision_digits=2):

        amount_in_words += _(' and %s ') % str(int(round(float_round(decimals*100, precision_rounding=1))))

    return amount_in_words



@api.onchange('amount_total')

def _onchange_amount_total(self):

    if hasattr(super(InvoiceTemplate, self), '_onchange_amount_total'):

        super(InvoiceTemplate, self)._onchange_amount_total()

    self.amount_in_words = self._get_amount_in_words(self.amount_total)

I am getting as out put: "five hundred and 78 Cents"

Upvotes: 0

Views: 78

Answers (1)

Bhoomi Vaishnani
Bhoomi Vaishnani

Reputation: 716

First you need to import this this file.

from odoo.tools import amount_to_text_en

Then write function which amount you want to convert to text.

@api.depends('amount_total')
   def _compute_text(self):
       for rec in self:
           rec.amount_in_word = amount_to_text_en(rec.amount_total, 'INR')

amount_in_word = fields.Char(string='Amount In Word', readonly=True,
       default=False, copy=False,  compute='_compute_text')

Upvotes: 2

Related Questions