在odoo11中找不到文本转换的数量

问题描述 投票:1回答:2

在odoo 10中,我们在amount_to_text_en.py中有odoo/tools文件。我在odoo 11中寻找类似的文件。但我找不到它。该怎么办 ?我是否需要在我的自定义模块中创建该文件,或者它是否存在于具有不同文件名的odoo11中?请帮忙。提前致谢 ..

odoo odoo-10 odoo-11
2个回答
1
投票

我认为这是你正在寻找的功能,

 @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

你可以在base/res/res_currency.py找到这个功能。

你可以像下面这样调用这个函数,

words = self.currency_id.with_context(lang=self.partner_id.lang or 'es_ES').amount_to_text(amount_i).upper()

我希望这能帮到您。


2
投票

或者只是将此范围添加到您的报告中:

<span t-if="doc.currency_id" t-esc="doc.currency_id.amount_to_text(doc.amount_total)"/> 
© www.soinside.com 2019 - 2024. All rights reserved.