From 81bca9769480e6285262927bb76ae0ba0614bb31 Mon Sep 17 00:00:00 2001 From: sesn-odoo Date: Thu, 14 Dec 2023 10:03:29 +0100 Subject: [PATCH] [FIX] base,l10n_gcc_invoice: apply the 'Total amount in letters' setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary ------- Currently, the 'Total amount of invoice in letters' setting doesn't do anything on GCC invoices. Steps to reproduce ------------------ * install `l10n_sa` * enable the Arabic language * in the settings, enable 'Total amount of invoice in letters' * create and print an invoice You should see that the amount in words in not displayed. Note: Currently, currency labels are not translatable. Since this isn't something that can be changed in stable version, it was decided to not include them in the Arabic amount in words. opw-3501112 opw-3485691 closes odoo/odoo#146364 X-original-commit: 1fb28f229c701ae1261dc502ef345ffda162f994 Signed-off-by: de Wouters de Bouchout Jean-Benoît (jbw) Signed-off-by: Séna Serge Nshimiyimana (sesn) --- addons/l10n_gcc_invoice/models/account_move.py | 17 +++++++++++++++++ .../l10n_gcc_invoice/views/report_invoice.xml | 11 +++++++++++ 2 files changed, 28 insertions(+) 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:
+ +

+

+ المبلغ الإجمالي
+ +

+
+