Skip to content

Commit

Permalink
fix unicode/ascii error
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s authored and hbrunn committed Jun 10, 2017
1 parent 561e8c5 commit 24546d7
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions partner_firstname/models/res_partner.py
Expand Up @@ -3,12 +3,10 @@
# © 2014 Agile Business Group (<http://www.agilebg.com>)
# © 2015 Grupo ESOC (<http://www.grupoesoc.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from odoo import api, fields, models
from .. import exceptions


_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -133,11 +131,20 @@ def _get_whitespace_cleaned_name(self, name, comma=False):
Removes leading, trailing and duplicated whitespace.
"""
if name:
name = u" ".join(name.split(None))
if comma:
name = name.replace(" ,", ",")
name = name.replace(", ", ",")
try:
name = u" ".join(name.split()) if name else name
except UnicodeDecodeError:
# with users coming from LDAP, name can be a str encoded as utf-8
# this happens with ActiveDirectory for instance, and in that case
# we get a UnicodeDecodeError during the automatic ASCII -> Unicode
# conversion that Python does for us.
# In that case we need to manually decode the string to get a
# proper unicode string.
name = u' '.join(name.decode('utf-8').split()) if name else name

if comma:
name = name.replace(" ,", ",")
name = name.replace(", ", ",")
return name

@api.model
Expand Down

0 comments on commit 24546d7

Please sign in to comment.