[FIX] models: blank export

Exporting One2many files gives blank export.

This reverts commit 2c61c54ffa.

opw-781399
opw-781457
This commit is contained in:
Nicolas Martinelli
2017-11-10 10:35:43 +01:00
parent a1ad6375ef
commit e77fa0051c
2 changed files with 31 additions and 33 deletions
+23 -31
View File
@@ -304,12 +304,13 @@ class test_m2o(CreatorCase):
[[False]])
def test_basic(self):
""" Exported value is empty
""" Exported value is the name_get of the related object
"""
record = self.env['export.integer'].create({'value': 42})
name = dict(record.name_get())[record.id]
self.assertEqual(
self.export(record.id),
[['']])
[[name]])
def test_path(self):
""" Can recursively export fields of m2o via path
@@ -351,13 +352,14 @@ class test_o2m(CreatorCase):
def test_single(self):
self.assertEqual(
self.export([(0, False, {'value': 42})]),
[['']])
# name_get result
[[u'export.one2many.child:42']])
def test_single_subfield(self):
self.assertEqual(
self.export([(0, False, {'value': 42})],
fields=['value', 'value/value']),
[['', u'42']])
[[u'export.one2many.child:42', u'42']])
def test_integrate_one_in_parent(self):
self.assertEqual(
@@ -379,13 +381,9 @@ class test_o2m(CreatorCase):
def test_multiple_records_name(self):
self.assertEqual(
self.export(self.commands, fields=['const', 'value']),
[
[u'4', ''],
['', ''],
['', ''],
['', ''],
['', ''],
])
[[
u'4', u','.join(self.names)
]])
def test_multiple_records_id(self):
export = self.export(self.commands, fields=['const', 'value/.id'])
@@ -403,18 +401,14 @@ class test_o2m(CreatorCase):
def test_multiple_records_with_name_before(self):
self.assertEqual(
self.export(self.commands, fields=['const', 'value', 'value/value']),
[
[u'4', '', u'4'],
['', '', u'42'],
['', '', u'36'],
['', '', u'4'],
['', '', u'13'],
])
[[ # exports sub-fields of very first o2m
u'4', u','.join(self.names), u'4'
]])
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', ''],
@@ -465,16 +459,16 @@ class test_o2m_multiple(CreatorCase):
def test_single_per_side(self):
self.assertEqual(
self.export(child1=False, child2=[(0, False, {'value': 42})]),
[[False, '']])
[[False, u'export.one2many.child.2:42']])
self.assertEqual(
self.export(child1=[(0, False, {'value': 43})], child2=False),
[['', False]])
[[u'export.one2many.child.1:43', False]])
self.assertEqual(
self.export(child1=[(0, False, {'value': 43})],
child2=[(0, False, {'value': 42})]),
[['', '']])
[[u'export.one2many.child.1:43', u'export.one2many.child.2:42']])
def test_single_integrate_subfield(self):
fields = ['const', 'child1/value', 'child2/value']
@@ -561,13 +555,14 @@ class test_m2m(CreatorCase):
def test_single(self):
self.assertEqual(
self.export([(0, False, {'value': 42})]),
[['']])
# name_get result
[[u'export.many2many.other:42']])
def test_single_subfield(self):
self.assertEqual(
self.export([(0, False, {'value': 42})],
fields=['value', 'value/value']),
[['', u'42']])
[[u'export.many2many.other:42', u'42']])
def test_integrate_one_in_parent(self):
self.assertEqual(
@@ -589,13 +584,10 @@ class test_m2m(CreatorCase):
def test_multiple_records_name(self):
self.assertEqual(
self.export(self.commands, fields=['const', 'value']),
[
[u'4', ''],
['', ''],
['', ''],
['', ''],
['', ''],
])
[[ # FIXME: hardcoded comma, import uses config.csv_internal_sep
# resolution: remove configurable csv_internal_sep
u'4', u','.join(self.names)
]])
# essentially same as o2m, so boring
+8 -2
View File
@@ -805,8 +805,14 @@ class BaseModel(object):
for j, val in enumerate(lines2[0]):
if val or isinstance(val, bool):
current[j] = val
# append the other lines at the end
lines += lines2[1:]
# 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:]
else:
current[i] = False