[FIX] core: use non-breaking space for currency symbol

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) <wan@odoo.com>
This commit is contained in:
Ivan Yelizariev
2022-05-10 13:22:42 +02:00
parent 33a49d2bd8
commit 5bf898d58a
2 changed files with 8 additions and 5 deletions
@@ -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,
}]])
+4 -2
View File
@@ -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