diff --git a/addons/l10n_gcc_invoice/models/account_move.py b/addons/l10n_gcc_invoice/models/account_move.py index 98888b7a190..9540b53ffdb 100644 --- a/addons/l10n_gcc_invoice/models/account_move.py +++ b/addons/l10n_gcc_invoice/models/account_move.py @@ -1,9 +1,19 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import logging + from odoo import fields, models, api +_logger = logging.getLogger(__name__) + +try: + from num2words import num2words +except ImportError: + _logger.warning("The num2words python library is not installed, amount-to-text features won't be fully available.") + num2words = None + class AccountMove(models.Model): _inherit = 'account.move' @@ -15,6 +25,13 @@ class AccountMove(models.Model): return 'l10n_gcc_invoice.arabic_english_invoice' return super()._get_name_invoice_report() + def _num2words(self, number, lang): + if num2words is None: + _logger.warning("The library 'num2words' is missing, cannot render textual amounts.") + return "" + + return num2words(number, lang=lang).title() + class AccountMoveLine(models.Model): _inherit = 'account.move.line' diff --git a/addons/l10n_gcc_invoice/views/report_invoice.xml b/addons/l10n_gcc_invoice/views/report_invoice.xml index 7b7f7d738d3..5e5fddbc2f0 100644 --- a/addons/l10n_gcc_invoice/views/report_invoice.xml +++ b/addons/l10n_gcc_invoice/views/report_invoice.xml @@ -432,6 +432,17 @@ +
+ Total amount in words:
+
+
+ المبلغ الإجمالي
+
+