[FIX] models: nonsensical special case in CSV export
Remove weird special case: when the first field of the first line of a one2many is empty, replace this first field by the comma-separated names of the lines, and discard the other lines.
This commit is contained in:
committed by
Nicolas Martinelli
parent
cc8f360039
commit
0d5ac92ff0
@@ -381,9 +381,13 @@ class test_o2m(CreatorCase):
|
||||
def test_multiple_records_name(self):
|
||||
self.assertEqual(
|
||||
self.export(self.commands, fields=['const', 'value']),
|
||||
[[
|
||||
u'4', u','.join(self.names)
|
||||
]])
|
||||
[
|
||||
[u'4', u'export.one2many.child:4'],
|
||||
[u'', u'export.one2many.child:42'],
|
||||
[u'', u'export.one2many.child:36'],
|
||||
[u'', u'export.one2many.child:4'],
|
||||
[u'', u'export.one2many.child:13'],
|
||||
])
|
||||
|
||||
def test_multiple_records_id(self):
|
||||
export = self.export(self.commands, fields=['const', 'value/.id'])
|
||||
@@ -401,19 +405,23 @@ class test_o2m(CreatorCase):
|
||||
def test_multiple_records_with_name_before(self):
|
||||
self.assertEqual(
|
||||
self.export(self.commands, fields=['const', 'value', 'value/value']),
|
||||
[[ # exports sub-fields of very first o2m
|
||||
u'4', u','.join(self.names), u'4'
|
||||
]])
|
||||
[
|
||||
[u'4', u'export.one2many.child:4', u'4'],
|
||||
['', u'export.one2many.child:42', u'42'],
|
||||
['', u'export.one2many.child:36', u'36'],
|
||||
['', u'export.one2many.child:4', u'4'],
|
||||
['', u'export.one2many.child:13', u'13'],
|
||||
])
|
||||
|
||||
def test_multiple_records_with_name_after(self):
|
||||
self.assertEqual(
|
||||
self.export(self.commands, fields=['const', 'value/value', 'value']),
|
||||
[ # completely ignores name_get request
|
||||
[u'4', u'4', ''],
|
||||
['', u'42', ''],
|
||||
['', u'36', ''],
|
||||
['', u'4', ''],
|
||||
['', u'13', ''],
|
||||
[
|
||||
[u'4', u'4', u'export.one2many.child:4'],
|
||||
['', u'42', u'export.one2many.child:42'],
|
||||
['', u'36', u'export.one2many.child:36'],
|
||||
['', u'4', u'export.one2many.child:4'],
|
||||
['', u'13', u'export.one2many.child:13'],
|
||||
])
|
||||
|
||||
def test_multiple_subfields_neighbour(self):
|
||||
@@ -584,10 +592,13 @@ class test_m2m(CreatorCase):
|
||||
def test_multiple_records_name(self):
|
||||
self.assertEqual(
|
||||
self.export(self.commands, fields=['const', 'value']),
|
||||
[[ # FIXME: hardcoded comma, import uses config.csv_internal_sep
|
||||
# resolution: remove configurable csv_internal_sep
|
||||
u'4', u','.join(self.names)
|
||||
]])
|
||||
[
|
||||
[u'4', u'export.many2many.other:4'],
|
||||
['', u'export.many2many.other:42'],
|
||||
['', u'export.many2many.other:36'],
|
||||
['', u'export.many2many.other:4'],
|
||||
['', u'export.many2many.other:13'],
|
||||
])
|
||||
|
||||
# essentially same as o2m, so boring
|
||||
|
||||
|
||||
+6
-10
@@ -797,22 +797,18 @@ class BaseModel(object):
|
||||
current[i] = ','.join(xml_ids) or False
|
||||
continue
|
||||
|
||||
# recursively export the fields that follow name
|
||||
fields2 = [(p[1:] if p and p[0] == name else []) for p in fields]
|
||||
# recursively export the fields that follow name; use
|
||||
# 'display_name' where no subfield is exported
|
||||
fields2 = [(p[1:] or ['display_name'] if p and p[0] == name else [])
|
||||
for p in fields]
|
||||
lines2 = value._export_rows(fields2)
|
||||
if lines2:
|
||||
# merge first line with record's main line
|
||||
for j, val in enumerate(lines2[0]):
|
||||
if val or isinstance(val, bool):
|
||||
current[j] = val
|
||||
# check value of current field
|
||||
if not current[i] and not isinstance(current[i], bool):
|
||||
# assign xml_ids, and forget about remaining lines
|
||||
xml_ids = [item[1] for item in value.name_get()]
|
||||
current[i] = ','.join(xml_ids)
|
||||
else:
|
||||
# append the other lines at the end
|
||||
lines += lines2[1:]
|
||||
# append the other lines at the end
|
||||
lines += lines2[1:]
|
||||
else:
|
||||
current[i] = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user