diff --git a/sql_view/wizards/sql_view_csv_preview.py b/sql_view/wizards/sql_view_csv_preview.py index 9ae80d58f..e6ba61fb3 100644 --- a/sql_view/wizards/sql_view_csv_preview.py +++ b/sql_view/wizards/sql_view_csv_preview.py @@ -22,9 +22,13 @@ import base64 from StringIO import StringIO -import unicodecsv +try: + import unicodecsv +except ImportError: + unicodecsv = None from openerp.osv import orm, fields +from openerp.tools.translate import _ class SQLViewCSVPreview(orm.TransientModel): @@ -65,6 +69,9 @@ class SQLViewCSVPreview(orm.TransientModel): headers = [desc[0] for desc in cr.description] records = cr.fetchall() filedata = StringIO() + if not unicodecsv: + raise orm.except_orm( + _('Error'), _('Please install the unicodecsv library')) try: writer = unicodecsv.writer(filedata, encoding='utf-8') writer.writerow(headers)