【问题标题】:Amount in text Odoo 10文本中的金额 Odoo 10
【发布时间】:2018-10-28 08:38:59
【问题描述】:

enter image description here我想把账户发票上显示的总金额转换成word,请帮忙。我无法解决它。我也已经尝试过了,但没有运气

【问题讨论】:

  • 请分享您已经尝试过的确切代码。这使得 stackoverflowers 可以为您提供帮助。

标签: odoo odoo-10


【解决方案1】:

您希望它在您的报告中还是记录在案?

报告

在 Odoo10 中,我通常这样做:

<t t-esc="o.amount_total" t-esc-options='{"widget": "num2words","case":"capital"}'/>

这里我们必须安装 num2words 模块才能正常工作。您可以通过

安装它

pip install num2words 或只是谷歌。

【讨论】:

    【解决方案2】:

    您可以使用以下方法解决您的问题。

    def Numbers_To_Words (number):
        dictionary = {'1': "one", '2': "two", '3': "three", '4': "four", '5': "five", '6': "six",
                '7': "seven", '8': "eight", '9': "nine", '0': "zero"}
        return " ".join(map(lambda x: dictionary[x], str(number)))
    
    print Numbers_To_Words(1234)
    

    【讨论】:

      【解决方案3】:

      python 中有 num2words 模块安装pip install num2wordsnum2words

      from num2words import num2words
      
      @api.multi
      def numtoword_s(self, amount_total):
          return (num2words(amount_total, lang='en_IN')).title()+" only"
      

      在发票文件中创建此函数并从 qweb 调用应用程序传递您要转换为文本格式的金额。

      【讨论】:

      • 我想在网络服务器中显示金额,而不是在报告中。
      • 我在问题上添加了一个屏幕截图,所以我希望在总金额之后显示 amount_to_text,我也尝试安装 num2words 但它返回错误ImportError: No module named num2words
      • 所以只需添加一个计算。你试过 pip install num2words 吗?
      • 添加代码,您尝试实现该功能。
      • 是的,我试过 pip install num2words 但它给了我一个错误。所以这是我的代码: class InvoiceTemplate(models.Model): _inherit = ['account.invoice'] text_amount=fields.Char(string='Total') @api.multi def numtoword_s(self, amount_total): return (num2words( amount_total, lang='en_IN')).title()+" only"
      【解决方案4】:

      这可能会帮助你:https://www.daniweb.com/programming/software-development/code/216839/number-to-word-converter-python

      还有这个 :https://pypi.org/project/inflect/ 这是一个 py 库,将您的数字表示为相关的单词

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-04
        • 1970-01-01
        • 1970-01-01
        • 2023-01-05
        • 2018-07-23
        • 2012-09-05
        • 1970-01-01
        • 2022-08-18
        相关资源
        最近更新 更多