[FIX] solve problem of importing data from csv with constraints available on object
authormra (Open ERP) <mra@tinyerp.com>
Wed, 18 Nov 2009 05:37:48 +0000 (11:07 +0530)
committermra (Open ERP) <mra@tinyerp.com>
Wed, 18 Nov 2009 05:37:48 +0000 (11:07 +0530)
bzr revid: mra@tinyerp.com-20091118053748-pmv0wxa5qp5n1qrx

bin/osv/orm.py

index a14286b..5318c24 100644 (file)
@@ -832,24 +832,27 @@ class orm_template(object):
             #try:
             (res, other, warning, translate, data_id, res_id) = \
                     process_liness(self, datas, [], current_module, self._name, fields_def)
-            if len(warning):                        
+            if len(warning):
                 cr.rollback()
                 return (-1, res, 'Line ' + str(counter) +' : ' + '!\n'.join(warning), '')
-            
+
             try:
                 id = ir_model_data_obj._update(cr, uid, self._name,
                      current_module, res, xml_id=data_id, mode=mode,
                      noupdate=noupdate, res_id=res_id, context=context)
             except Exception, e:
                 import psycopg2
+                import osv
                 if isinstance(e,psycopg2.IntegrityError):
-                    msg= _('Insertion Failed!')
+                    msg= _('Insertion Failed! ')
                     for key in self.pool._sql_error.keys():
                         if key in e[0]:
                             msg = self.pool._sql_error[key]
                             break
-                    return (-1, res,'Line ' + str(counter) +' : ' + msg,'' )
-                
+                    return (-1, res, 'Line ' + str(counter) +' : ' + msg, '' )
+                if isinstance(e, osv.orm.except_orm ):
+                    msg = _('Insertion Failed! ' + e[1])
+                    return (-1, res, 'Line ' + str(counter) +' : ' + msg, '' )
             for lang in translate:
                 context2 = context.copy()
                 context2['lang'] = lang