【问题标题】:Amount to text conversion not found in odoo11在odoo11中找不到文本转换量
【发布时间】:2018-06-14 07:03:34
【问题描述】:

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

【问题讨论】:

    标签: odoo odoo-10 odoo-11


    【解决方案1】:

    或者只是将此跨度添加到您的报告中:

    <span t-if="doc.currency_id" t-esc="doc.currency_id.amount_to_text(doc.amount_total)"/> 
    

    【讨论】:

      【解决方案2】:

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

       @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()
      

      希望对你有帮助。

      【讨论】:

      • 非常感谢.. 目前我正在处理另一个项目,当我开始工作时会恢复..
      猜你喜欢
      • 2013-08-07
      • 1970-01-01
      • 2014-10-01
      • 2012-05-22
      • 2020-06-20
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多