Don't commit in the middle of loading modules
[odoo/odoo.git] / bin / tools / convert.py
index a8e1481..4f6fb9a 100644 (file)
@@ -13,14 +13,6 @@ import netsvc
 from config import config
 import logging
 
-# Number of imported lines between two commit (see convert_csv_import()):
-COMMIT_STEP = 500
-
-
-
-# Number of imported lines between two commit (see convert_csv_import()):
-COMMIT_STEP = 500 
-
 
 class ConvertError(Exception):
        def __init__(self, doc, orig_excpt):
@@ -239,7 +231,7 @@ class xml_import(object):
                xml_id = rec.getAttribute('id').encode('utf8')
                self._test_xml_id(xml_id)
                id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.report.xml", self.module, res, xml_id, mode=self.mode)
-               self.idref[xml_id] = id
+               self.idref[xml_id] = int(id)
                if not rec.hasAttribute('menu') or eval(rec.getAttribute('menu')):
                        keyword = str(rec.getAttribute('keyword') or 'client_print_multi')
                        keys = [('action',keyword),('res_model',res['model'])]
@@ -266,9 +258,9 @@ class xml_import(object):
                res = {'name': string, 'wiz_name': name, 'multi':multi}
 
                id = self.pool.get('ir.model.data')._update(cr, self.uid, "ir.actions.wizard", self.module, res, xml_id, mode=self.mode)
-               self.idref[xml_id] = id
+               self.idref[xml_id] = int(id)
                # ir_set
-               if not rec.hasAttribute('menu') or eval(rec.getAttribute('menu')):
+               if (not rec.hasAttribute('menu') or eval(rec.getAttribute('menu'))) and id:
                        keyword = str(rec.getAttribute('keyword') or 'client_action_multi')
                        keys = [('action',keyword),('res_model',model)]
                        value = 'ir.actions.wizard,'+str(id)
@@ -295,7 +287,7 @@ class xml_import(object):
                res = {'name': name, 'type': type, 'view_id': view_id, 'domain': domain, 'context': context, 'res_model': res_model, 'src_model': src_model, 'view_type': view_type, 'view_mode': view_mode, 'usage': usage }
 
                id = self.pool.get('ir.model.data')._update(cr, self.uid, 'ir.actions.act_window', self.module, res, xml_id, mode=self.mode)
-               self.idref[xml_id] = id
+               self.idref[xml_id] = int(id)
 
                if src_model:
                        keyword = 'client_action_relate'
@@ -414,7 +406,7 @@ class xml_import(object):
                                # the menuitem does't exist but we are in branch (not a leaf)
                                pid = self.pool.get('ir.ui.menu').create(cr, self.uid, {'parent_id' : pid, 'name' : menu_elem})
                if rec_id and pid:
-                       self.idref[rec_id] = pid
+                       self.idref[rec_id] = int(pid)
 
                if rec.hasAttribute('action') and pid:
                        a_action = rec.getAttribute('action').encode('utf8')
@@ -509,7 +501,7 @@ class xml_import(object):
                                if id:
                                        # if it existed, we don't update the data, but we need to
                                        # know the id of the existing record anyway
-                                       self.idref[rec_id] = id
+                                       self.idref[rec_id] = int(id)
                                        return None
                                else:
                                        # if the resource didn't exist
@@ -564,7 +556,7 @@ class xml_import(object):
                        res[f_name] = f_val
                id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode )
                if rec_id:
-                       self.idref[rec_id] = id
+                       self.idref[rec_id] = int(id)
                return rec_model, id
 
        def id_get(self, cr, model, id_str):
@@ -574,7 +566,7 @@ class xml_import(object):
                if '.' in id_str:
                        mod,id_str = id_str.split('.')
                result = self.pool.get('ir.model.data')._get_id(cr, self.uid, mod, id_str)
-               return self.pool.get('ir.model.data').read(cr, self.uid, [result], ['res_id'])[0]['res_id']
+               return int(self.pool.get('ir.model.data').read(cr, self.uid, [result], ['res_id'])[0]['res_id'])
 
        def parse(self, xmlstr):
                d = xml.dom.minidom.parseString(xmlstr)
@@ -589,7 +581,6 @@ class xml_import(object):
                                                        self.logger.notifyChannel("init", netsvc.LOG_INFO, '\n'+rec.toxml())
                                                        self.cr.rollback()
                                                        raise
-               self.cr.commit()
                return True
 
        def __init__(self, cr, module, idref, mode, report=assertion_report(), noupdate = False):
@@ -616,13 +607,13 @@ class xml_import(object):
                        'act_window': self._tag_act_window,
                }
 
-#
-# Import a CSV file:
-#     quote: "
-#     delimiter: ,
-#     encoding: UTF8
-#
+CSV_STEP = 500
+
 def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', noupdate=False):
+       '''Import csv file :
+               quote: "
+               delimiter: ,
+               encoding: utf-8'''
        if not idref:
                idref={}
        model = ('.'.join(fname.split('.')[:-1]).split('-'))[0]
@@ -642,14 +633,11 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', n
        datas = []
        for line in reader:
                datas.append( map(lambda x:x.decode('utf8').encode('utf8'), line))
-               if len(datas) > COMMIT_STEP:
+               if len(datas) > CSV_STEP:
                        pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate)
-                       cr.commit()
                        datas=[]
-
        if datas:
                pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate)
-               cr.commit()
 
 #
 # xml import/export