Partial Commit
bzr revid: fp@tinyerp.com-20080819132612-06llazok11knlwr7
This commit is contained in:
+11
-2
@@ -53,6 +53,8 @@ import string
|
||||
import netsvc
|
||||
import re
|
||||
|
||||
import pickle
|
||||
|
||||
import fields
|
||||
import tools
|
||||
|
||||
@@ -432,7 +434,7 @@ class orm_template(object):
|
||||
return datas
|
||||
|
||||
def import_data(self, cr, uid, fields, datas, mode='init',
|
||||
current_module=None, noupdate=False, context=None):
|
||||
current_module=None, noupdate=False, context=None, filename=None):
|
||||
if not context:
|
||||
context = {}
|
||||
fields = map(lambda x: x.split('/'), fields)
|
||||
@@ -591,7 +593,10 @@ class orm_template(object):
|
||||
fields_def = self.fields_get(cr, uid, context=context)
|
||||
done = 0
|
||||
|
||||
initial_size = len(datas)
|
||||
counter = 0
|
||||
while len(datas):
|
||||
counter += 1
|
||||
res = {}
|
||||
#try:
|
||||
(res, other, warning, translate, data_id) = \
|
||||
@@ -606,8 +611,12 @@ class orm_template(object):
|
||||
context2 = context.copy()
|
||||
context2['lang'] = lang
|
||||
self.write(cr, uid, [id], translate[lang], context2)
|
||||
if config.get('import_partial', False):
|
||||
if config.get('import_partial', False) and filename: # and (not (counter%100)) :
|
||||
data = pickle.load(file(config.get('import_partial')))
|
||||
data[filename] = initial_size - len(datas) + data.get(filename, 0)
|
||||
pickle.dump(data, file(config.get('import_partial'),'wb'))
|
||||
cr.commit()
|
||||
|
||||
#except Exception, e:
|
||||
# logger.notifyChannel("import", netsvc.LOG_ERROR, e)
|
||||
# cr.rollback()
|
||||
|
||||
@@ -724,6 +724,10 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
input = StringIO.StringIO(csvcontent)
|
||||
reader = csv.reader(input, quotechar='"', delimiter=',')
|
||||
fields = reader.next()
|
||||
|
||||
import pickle
|
||||
if config.get('import_partial'):
|
||||
if not os.path.isfile(config.get('import_partial')):
|
||||
@@ -732,10 +736,9 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
|
||||
if fname in data:
|
||||
if not data[fname]:
|
||||
return
|
||||
|
||||
input = StringIO.StringIO(csvcontent)
|
||||
reader = csv.reader(input, quotechar='"', delimiter=',')
|
||||
fields = reader.next()
|
||||
else:
|
||||
for i in range(data[fname]):
|
||||
reader.next()
|
||||
|
||||
if not (mode == 'init' or 'id' in fields):
|
||||
return
|
||||
@@ -746,7 +749,7 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init',
|
||||
if (not line) or not reduce(lambda x,y: x or y, line) :
|
||||
continue
|
||||
datas.append( map(lambda x:x.decode('utf8').encode('utf8'), line))
|
||||
pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate)
|
||||
pool.get(model).import_data(cr, uid, fields, datas,mode, module,noupdate,filename=fname)
|
||||
if config.get('import_partial'):
|
||||
data = pickle.load(file(config.get('import_partial')))
|
||||
data[fname] = 0
|
||||
|
||||
Reference in New Issue
Block a user