[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) <nim@odoo.com>
Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
Nasreddin (bon)
2020-06-24 11:06:01 +00:00
parent c219727974
commit 3c169a415b
2 changed files with 18 additions and 1 deletions
+16 -1
View File
@@ -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('русский алфавит'), 'русскии алфавит')
+2
View File
@@ -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)])