如何在odoo 11中将发票的总价转换为字母?

时间:2019-06-05 17:56:57

标签: odoo odoo-11

我创建了一个名为“ custom_report_module”的模块,在该模块中可以制作个性化发票...发票效果很好,但是我想将总额添加为字母...例如,如果购买的金额达到我打印的500,000字母“是:五十万瓜拉尼”或“是:五十万瓜拉尼”

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

我的xml

<span t-esc="l.amount_to_text(l.price_unit, l.price_unit)"/>

1 个答案:

答案 0 :(得分:0)

请看一下这段代码

@api.multi
def amount_to_text(self, amount):
    self.ensure_one()
    def _num2words(number, lang):
        try:
            return num2words(number, lang=lang).title()
        except NotImplementedError:
            return num2words(number, lang='en').title()

    if num2words is None:
        logging.getLogger(__name__).warning("The library 'num2words' is missing, cannot render textual amounts.")
        return ""

    formatted = "%.{0}f".format(self.decimal_places) % amount
    parts = formatted.partition('.')
    integer_value = int(parts[0])
    fractional_value = int(parts[2] or 0)

    lang_code = self.env.context.get('lang') or self.env.user.lang
    lang = self.env['res.lang'].search([('code', '=', lang_code)])
    amount_words = tools.ustr('{amt_value} {amt_word}').format(
                    amt_value=_num2words(integer_value, lang=lang.iso_code),
                    amt_word=self.currency_unit_label,
                    )
    if not self.is_zero(amount - integer_value):
        amount_words += ' ' + _('and') + tools.ustr(' {amt_value} {amt_word}').format(
                    amt_value=_num2words(fractional_value, lang=lang.iso_code),
                    amt_word=self.currency_subunit_label,
                    )
    return amount_words