From 3c169a415b2f5155479af03f791fbf97d438231d Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Tue, 23 Jun 2020 09:22:31 +0000 Subject: [PATCH] [FIX] tools: Return input_str when removing accents if empty Issue The misc feature remove_accents(input_str) return a string 'False' if the param is a boolean. Solution Return input_str if equal '' or False. opw-2278959 closes odoo/odoo#53572 X-original-commit: 3fc7ce3b5599355933734e5e3f59d14a7a9b199c Related: odoo/enterprise#11391 Signed-off-by: Nicolas Martinelli (nim) Signed-off-by: bon-odoo --- odoo/addons/base/tests/test_misc.py | 17 ++++++++++++++++- odoo/tools/misc.py | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/tests/test_misc.py b/odoo/addons/base/tests/test_misc.py index b37ee11246a..2cf2ebc7842 100644 --- a/odoo/addons/base/tests/test_misc.py +++ b/odoo/addons/base/tests/test_misc.py @@ -5,7 +5,7 @@ import datetime from dateutil.relativedelta import relativedelta import pytz -from odoo.tools import misc, date_utils, merge_sequences +from odoo.tools import misc, date_utils, merge_sequences, remove_accents from odoo.tests.common import TransactionCase, BaseCase @@ -302,3 +302,18 @@ class TestGroupCalls(BaseCase): callbacks.clear() callbacks() self.assertEqual(log, ["foo", 1, 2, "baz"]) + + +class TestRemoveAccents(BaseCase): + def test_empty_string(self): + self.assertEqual(remove_accents(False), False) + self.assertEqual(remove_accents(''), '') + self.assertEqual(remove_accents(None), None) + + def test_latin(self): + self.assertEqual(remove_accents('Niño Hernández'), 'Nino Hernandez') + self.assertEqual(remove_accents('Anaïs Clémence'), 'Anais Clemence') + + def test_non_latin(self): + self.assertEqual(remove_accents('العربية'), 'العربية') + self.assertEqual(remove_accents('русский алфавит'), 'русскии алфавит') diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index e7f087f1636..e1dc069cddb 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -754,6 +754,8 @@ def remove_accents(input_str): """Suboptimal-but-better-than-nothing way to replace accented latin letters by an ASCII equivalent. Will obviously change the meaning of input_str and work only for some cases""" + if not input_str: + return input_str input_str = ustr(input_str) nkfd_form = unicodedata.normalize('NFKD', input_str) return u''.join([c for c in nkfd_form if not unicodedata.combining(c)])