From 5bf898d58a0062504faad43ef3840af4b2e43b23 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Tue, 26 Apr 2022 14:08:59 +0000 Subject: [PATCH] [FIX] core: use non-breaking space for currency symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some languages and layout the currency symbol might be wrapped in a separate line, which is not acceptable from accounting point of view. Fix it by replacing space with a special symbol. STEPS for v15: * install MX localization; * create a Spanish speaking customer * generate a pdf: 1) Create quotation with products 2) Add IVA 16%tax 3) print a report BEFORE: the currency symbol is incorrectly displayed on a separate line AFTER: currency symbol is always with the amount --- https://github.com/odoo/odoo/pull/89722 opw-2829138 closes odoo/odoo#90961 X-original-commit: 684687226b87022bc9f9ba7667b295e545100645 Related: odoo/enterprise#27138 Signed-off-by: William André (wan) --- addons/account_check_printing/tests/test_print_check.py | 7 ++++--- odoo/tools/misc.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/account_check_printing/tests/test_print_check.py b/addons/account_check_printing/tests/test_print_check.py index c3b343e2485..e82a14930f9 100644 --- a/addons/account_check_printing/tests/test_print_check.py +++ b/addons/account_check_printing/tests/test_print_check.py @@ -2,6 +2,7 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon from odoo.addons.account_check_printing.models.account_payment import INV_LINES_PER_STUB from odoo.tests import tagged +from odoo.tools.misc import NON_BREAKING_SPACE import math @@ -124,8 +125,8 @@ class TestPrintCheck(AccountTestInvoicingCommon): self.assertEqual(stub_pages, [[{ 'due_date': '01/01/2016', 'number': invoice.name, - 'amount_total': '$ 100.00', - 'amount_residual': '$ 50.00', - 'amount_paid': '150.000 ☺', + 'amount_total': f'${NON_BREAKING_SPACE}100.00', + 'amount_residual': f'${NON_BREAKING_SPACE}50.00', + 'amount_paid': f'150.000{NON_BREAKING_SPACE}☺', 'currency': invoice.currency_id, }]]) diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 7d7bb1fea5b..93dab1664cf 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -59,6 +59,8 @@ SKIPPED_ELEMENT_TYPES = (etree._Comment, etree._ProcessingInstruction, etree.Com # Configure default global parser etree.set_default_parser(etree.XMLParser(resolve_entities=False)) +NON_BREAKING_SPACE = u'\N{NO-BREAK SPACE}' + #---------------------------------------------------------- # Subprocesses #---------------------------------------------------------- @@ -1316,9 +1318,9 @@ def formatLang(env, value, digits=None, grouping=True, monetary=False, dp=False, if currency_obj and currency_obj.symbol: if currency_obj.position == 'after': - res = '%s %s' % (res, currency_obj.symbol) + res = '%s%s%s' % (res, NON_BREAKING_SPACE, currency_obj.symbol) elif currency_obj and currency_obj.position == 'before': - res = '%s %s' % (currency_obj.symbol, res) + res = '%s%s%s' % (currency_obj.symbol, NON_BREAKING_SPACE, res) return res