[MERGE] import: support for comma-separated ids in one2many, actually link the records.
- not a real merge, as I just recovered the diff. original code by tfr. bzr revid: vmt@openerp.com-20110719122802-64jxm0h5uftsf94k
This commit is contained in:
+27
-18
@@ -1091,7 +1091,20 @@ class orm_template(object):
|
||||
if line[i] and skip:
|
||||
return False
|
||||
continue
|
||||
|
||||
#set the mode for m2o, o2m, m2m : xml_id/id/name
|
||||
if len(field) == len(prefix)+1:
|
||||
mode = False
|
||||
else:
|
||||
mode = field[len(prefix)+1]
|
||||
|
||||
# TODO: improve this by using csv.csv_reader
|
||||
def many_ids(line, relation, current_module, mode):
|
||||
res = []
|
||||
for db_id in line.split(config.get('csv_internal_sep')):
|
||||
res.append(_get_id(relation, db_id, current_module, mode))
|
||||
return [(6,0,res)]
|
||||
|
||||
# ID of the record using a XML ID
|
||||
if field[len(prefix)]=='id':
|
||||
try:
|
||||
@@ -1111,10 +1124,13 @@ class orm_template(object):
|
||||
if field[len(prefix)] in done:
|
||||
continue
|
||||
done[field[len(prefix)]] = True
|
||||
relation_obj = self.pool.get(fields_def[field[len(prefix)]]['relation'])
|
||||
relation = fields_def[field[len(prefix)]]['relation']
|
||||
relation_obj = self.pool.get(relation)
|
||||
newfd = relation_obj.fields_get( cr, uid, context=context )
|
||||
pos = position
|
||||
res = []
|
||||
|
||||
res = many_ids(line[i], relation, current_module, mode)
|
||||
|
||||
first = 0
|
||||
while pos < len(datas):
|
||||
res2 = process_liness(self, datas, prefix + [field[len(prefix)]], current_module, relation_obj._name, newfd, pos, first)
|
||||
@@ -1124,30 +1140,23 @@ class orm_template(object):
|
||||
nbrmax = max(nbrmax, pos)
|
||||
warning += w2
|
||||
first += 1
|
||||
|
||||
if data_res_id2:
|
||||
res.append((4, data_res_id2))
|
||||
|
||||
if (not newrow) or not reduce(lambda x, y: x or y, newrow.values(), 0):
|
||||
break
|
||||
|
||||
res.append( (data_res_id2 and 1 or 0, data_res_id2 or 0, newrow) )
|
||||
|
||||
|
||||
elif fields_def[field[len(prefix)]]['type']=='many2one':
|
||||
relation = fields_def[field[len(prefix)]]['relation']
|
||||
if len(field) == len(prefix)+1:
|
||||
mode = False
|
||||
else:
|
||||
mode = field[len(prefix)+1]
|
||||
res = _get_id(relation, line[i], current_module, mode)
|
||||
|
||||
elif fields_def[field[len(prefix)]]['type']=='many2many':
|
||||
relation = fields_def[field[len(prefix)]]['relation']
|
||||
if len(field) == len(prefix)+1:
|
||||
mode = False
|
||||
else:
|
||||
mode = field[len(prefix)+1]
|
||||
|
||||
# TODO: improve this by using csv.csv_reader
|
||||
res = []
|
||||
for db_id in line[i].split(config.get('csv_internal_sep')):
|
||||
res.append( _get_id(relation, db_id, current_module, mode) )
|
||||
res = [(6,0,res)]
|
||||
res = many_ids(line[i], relation, current_module, mode)
|
||||
|
||||
elif fields_def[field[len(prefix)]]['type'] == 'integer':
|
||||
res = line[i] and int(line[i]) or 0
|
||||
@@ -1168,7 +1177,7 @@ class orm_template(object):
|
||||
|
||||
else:
|
||||
res = line[i]
|
||||
|
||||
|
||||
row[field[len(prefix)]] = res or False
|
||||
|
||||
result = (row, nbrmax, warning, data_res_id, xml_id)
|
||||
@@ -1182,7 +1191,7 @@ class orm_template(object):
|
||||
position = 0
|
||||
while position<len(datas):
|
||||
res = {}
|
||||
|
||||
|
||||
(res, position, warning, res_id, xml_id) = \
|
||||
process_liness(self, datas, [], current_module, self._name, fields_def, position=position)
|
||||
if len(warning):
|
||||
|
||||
Reference in New Issue
Block a user