From b850cfe3e582ba967cec57c97b4ce4563f7de171 Mon Sep 17 00:00:00 2001
From: "ame (Tiny/Axelor)" <ame@tinyerp.com>
Date: Thu, 12 Feb 2009 19:02:52 +0530
Subject: [PATCH] [FIX] unicode proble.

lp bug: https://launchpad.net/bugs/327294 fixed

bzr revid: ame@tinyerp.com-20090212133252-wludmq0d95irp6dm
---
 bin/osv/fields.py |  8 ++------
 bin/tools/misc.py | 14 +++++++++++---
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/bin/osv/fields.py b/bin/osv/fields.py
index 99b39ed9c65d..b44579957c46 100644
--- a/bin/osv/fields.py
+++ b/bin/osv/fields.py
@@ -155,12 +155,8 @@ class char(_column):
 
         # we need to convert the string to a unicode object to be able
         # to evaluate its length (and possibly truncate it) reliably
-        if isinstance(symb, str):
-            u_symb = unicode(symb, 'utf8')
-        elif isinstance(symb, unicode):
-            u_symb = symb
-        else:
-            u_symb = unicode(symb)
+        u_symb = tools.ustr(symb)
+
         return u_symb[:self.size].encode('utf8')
 
 
diff --git a/bin/tools/misc.py b/bin/tools/misc.py
index 4389ee588e0f..5eee773f0f12 100644
--- a/bin/tools/misc.py
+++ b/bin/tools/misc.py
@@ -677,11 +677,19 @@ def ustr(value):
     if not isinstance(value, str):
         value = str(value)
 
-    try:
+    try: # first try utf-8
         return unicode(value, 'utf-8')
     except:
-        from locale import getlocale
-        return unicode(value, getlocale()[1])
+        pass
+
+    try: # then extened iso-8858
+        return unicode(value, 'iso-8859-15')
+    except:
+        pass
+
+    # else use default system locale
+    from locale import getlocale
+    return unicode(value, getlocale()[1])
 
 def exception_to_unicode(e):
     if hasattr(e, 'message'):
-- 
GitLab